in reply to multiple (different) substitutions on same $foo
I don't know if it is a good idea or not, but yes, it is possible.
for ( $foo ) { s/frog/toad/g; s/man/boy/; s/woman/girl/; }
Explanation: This is equivalent to the following where the default and magic $_ variable is implicit in several locations:
for $_ ( $foo ) { $_ =~ s/frog/toad/g; $_ =~ s/man/boy/; $_ =~ s/woman/girl/; }
Another magic thing going on here is that the $_ is aliased to the value(s) in the list so that the substitutions are actually modifying $foo.
-- Eric Hammond
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: multiple (different) substitutions on same $foo
by welchavw (Pilgrim) on Aug 22, 2003 at 13:44 UTC | |
Re: Re: multiple (different) substitutions on same $foo
by jonnyfolk (Vicar) on Aug 22, 2003 at 07:39 UTC | |
by esh (Pilgrim) on Aug 22, 2003 at 08:01 UTC | |
by Arbogast (Monk) on Aug 22, 2003 at 16:06 UTC | |
by jonnyfolk (Vicar) on Aug 22, 2003 at 18:46 UTC |