Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl6: do I need the @-sigil for userdefined variables?

Is there something I can't do without the '@'-sigil when working with user-defined variables?

#!perl6
use v6;

my $list = <a b c d e f>;
my @list = <a b c d e f>;

$list.list.perl.say;
@list.perl.say; 

$list[2..4].say;
@list[2..4].say;

$list.elems.say;
@list.elems.say;

$list.end.say;
@list.end.say;

say 'OK' if $list ~~ /^c$/;
say 'OK' if @list ~~ /^c$/;
like image 656
sid_com Avatar asked Feb 18 '11 08:02

sid_com


1 Answers

Yes, variadic parameters require the @ sigil:

sub SHOUT(*@a) {
      print @a>>.uc;
}

Though that's cheating your question, because @a is now a formal parameter, not just a variable. For actual variables only, scalars can do everything you need, though often with more effort than if you use the appropriate sigil.

like image 69
moritz Avatar answered Nov 06 '22 14:11

moritz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!