G'day...
On Wed, 2004-11-24 at 23:00, FlashMX wrote:
> Could you give an example of using grep on a array to do a replace?
grep example:
if (grep(/bazza/i, @myarray)) {
print "Bazza's home!\n";
}
OR
my @bazza_list = grep {/bazza/i} @myarray;
(Either form is fine)
However to do a replace, I'd be more likely to use something like map.
grep is a search function... map can work well as a replacement function (I
think of map as map one set of values to another set of values...)
E.g.
my @new_array = map { s/old/new/gi } @old_array;
Really map just goes through your list, mapping each item to $_ and performs
the given expression on them...\
(Err.. I think the example above actually modifies the contents of @old_array
...)
See http://www.raycosoft.com/rayco/support/perl_tutor.html for instructions and
examples on these functions...
HTH...
All the best...
-Mike
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>