my $bar = \@foo; # Perl 5 print $bar->[5], "\n";
my $bar = \@foo; # Perl 6 print $bar.[5], "\n";
my $bar = @foo; print $bar.[5], "\n";
my $bar = @foo; say $bar.[5];
my $bar = @foo; say $bar[5];
my $bar = @foo; say $bar[5]; # Not related to @bar!
my @xyzzy = (42, 15, 123); say @xyzzy[2]; # 123\n
my @xyzzy = 42, 15, 123; say @xyzzy[2]; # 123\n
my @xyzzy = 42, 15, 123; grep { $_ == 15 }, @xyzzy;
my @xyzzy = 42, 15, 123; @xyzzy ~~ 15; # true
my @xyzzy = 42, 15, 123; @xyzzy ~~ 16; # false
$string ~~ /regex/;
grammar POD { token document { <paragraph>* } token paragraph { <verbatim> | <command> | <ordinary> } token verbatim { (<ws> .*?) <?par_end> } token command { =<command_name> <?ws> <text> <?par_end> } ... }
my $tree = $pod ~~ /<POD::document>/;
sub hello ($what) { say "Hello, { ucfirst $what }!"; } hello 'world';
sub hello ($what) { say "Hello, { $what.ucfirst }!"; } hello 'world';
sub hello ($what = 'world') { say "Hello, { ucfirst $what }!"; } hello 'austria'; # Hello, Austria! hello; # Hello, World!
hello what => 'austria'; hello :what('austria');
sub hello (:$what = 'world') { ... } hello 'world'; # Error!
say hello (@what) { for @what -> $what { say "Hello, { $what.ucfirst }!"; } }
say hello (@what) { for @what { say "Hello, { $_.ucfirst }!"; } }
say hello (@what) { for @what { say "Hello, { .ucfirst }!"; } }
say hello (@what) { say "Hello, { .ucfirst }!" for @what; } my @places = qw(austria world); hello @places;
say hello (@what) { say "Hello, { .ucfirst }!" for @what; } my @places = <austria world>; hello @places;
say hello (@what) { say "Hello, { .ucfirst }!" for @what; } hello <austria world>; # Error!
say hello (*@what) { say "Hello, { .ucfirst }!" for @what; } hello <austria world>; # Works!
sub foo { ... }
sub foo (*@_) { ... }
sub foo { my ($bar, $quux) = @_; ... }
my $index = 0; for @items -> $item { say "{ $index++ } => $item"; ... }
my $index = 0; for @items -> $item { say "{ $index++ } => $item"; ... debug "Done with $index"; # bug! }
for each(@items; 0..@items.last) -> $item, $index { say "$index => $item"; ... debug "Done with $index"; }
for each(@items; 0..Inf) -> $item, $index { say "$index => $item"; ... debug "Done with $index"; }
for each(@items; 0..*) -> $item, $index { say "$index => $item"; ... debug "Done with $index"; }
sub hex_color ($name) { ▼ switch construct given $name { when 'red' { return '#ff0000' } when 'green' { return '#00ff00' } when 'blue' { return '#0000ff' } ▼ "whatever" operator when * { ▼ concatenation operator return '#' ~ { any(0..9, 'a'..'f').pick } x 6; ▲_____junction____▲ ▲__________closure_________▲ } ▼ flexible croaking fail "Color '$name' unknown"; } }