in reply to Re^2: 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

holli,
Would you expect "cold" =~ s/cold/new/; to work? Remember that the looping variable in a Perl style for loop is an alias to that which is being looped over.

Cheers - L~R

  • Comment on Re^3: Using eval to s/// with a pattern supplied on the command-line
  • Download Code

Replies are listed 'Best First'.
Re^4: Using eval to s/// with a pattern supplied on the command-line
by holli (Abbot) on Mar 17, 2005 at 05:52 UTC
    No, I don't. But the regex operates on $_ and therefore I would have expected to be changeable.


    holli, /regexed monk/
      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