简体   繁体   中英

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$/;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM