in reply to Re^3: Using eval to s/// with a pattern supplied on the command-line
in thread Using eval to s/// with a pattern supplied on the command-line

No, I don't. But the regex operates on $_ and therefore I would have expected to be changeable.


holli, /regexed monk/
  • Comment on Re^4: Using eval to s/// with a pattern supplied on the command-line
  • Download Code

Replies are listed 'Best First'.
Re^5: Using eval to s/// with a pattern supplied on the command-line
by Limbic~Region (Chancellor) on Mar 17, 2005 at 13:13 UTC
    holli,
    But as I said, $_ isn't a copy it is an alias. If you were to do the following:
    my @word = qw(one two three four five); for ( @word ) { $_ = uc( $_ ); } print "$_\n" for @word;
    You find the underlying array being modified. If the thing being looped over can't be modified you can't change the looping variable. You need to make an explicit copy if you want to do that.

    Cheers - L~R