Ahhh, I see. So this would work as well.
map {s/foo/bar/} @data;
....But the "for" seems to be a little bit faster which makes sense.
Benchmark: timing 1000000 iterations of FOR, MAP...
FOR: 16 wallclock secs (15.84 usr + 0.00 sys = 15.84 CPU) @ 63119.36/s
(n=1000000)
MAP: 19 wallclock secs (18.87 usr + 0.00 sys = 18.87 CPU) @ 52982.94/s
(n=1000000)
Thanks.
Rob
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 04, 2002 1:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Using =~ with a list
>>>>> "Randal" == Randal L Schwartz <[EMAIL PROTECTED]> writes:
>>>>> "Robert" == Robert Hanson <[EMAIL PROTECTED]> writes:
Robert> You probably want to use "map".
Robert> This should work.
Robert> @body = map { s/foo/bar/; $_ } (@body);
Randal> No. Please don't answer without testing.
Randal> That messes up @body as well, since $_ is an alias back into the
Randal> original list.
And of course, I need to read better. :) I was thinking it was
@new = map { s/foo/bar; $_ } @body;
So Robert's solution was just plain wierd, although it will do the
job. It's a bit like saying "$a = $a = 3 + $b". Why the second
assignment? :)
Randal> This works:
Randal> s/foo/bar/ for @body;
Randal> presuming you have a reasonably modern Perl.
And can read your own handwriting. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]