in reply to updating an array of strings
This will replace all occurances of 'baz' in the array however. You didn't specify if this is okay or not.use strict; my @array = qw(foo bar bazzle baz); @array = map { s/^baz$/qux/;$_ } @array;
UPDATE: oops - yet another problem to not solve with map. Thanks for the tip grantm and Anony. :)
So ... let's say that you only wanted to replace the first occurrance of 'baz':much better, just don't try this with a list:my @array = qw(foo bazzle baz baz); for (@array) { last if s/^baz$/qux/; }
which will not work, because you are trying to modify read-only values.for (qw(foo bazzle baz baz)) { last if s/^baz$/qux/; }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: updating an array of strings
by Anonymous Monk on Aug 26, 2002 at 01:35 UTC | |
|
Re: (jeffa) Re: updating an array of strings
by grantm (Parson) on Aug 26, 2002 at 01:41 UTC | |
|
Re: (jeffa) Re: updating an array of strings
by kirk123 (Beadle) on Aug 26, 2002 at 01:49 UTC |