in reply to Re^5: regex syntax and idomatic Perl
in thread regex syntax and idomatic Perl
So ... $_ in the for loop, and $y are references
Not exactly, $_ is an alias to the elements being looped over, not a reference (which would need to be dereferenced), see the first few paragraphs of Foreach Loops. Some more fun with aliases, note how the magic substr lvalue remembers its bounds in the string:
our ($x,$y) = "Hello, World!"; *y = \substr $x, 7, 5; # alias via glob $y = "substring"; print "<$x>\n"; # prints <Hello, substring!> $y = "Perl"; print "<$x>\n"; # prints <Hello, Perl!> $x = "Magic, cool stuff!"; print "<$y>\n"; # prints <cool>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: regex syntax and idomatic Perl
by cbeckley (Curate) on Mar 23, 2017 at 14:44 UTC |