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)
In reply to (jeffa) Re: updating an array of strings
by jeffa
in thread updating an array of strings
by kirk123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |