Monkomatic has asked for the wisdom of the Perl Monks concerning the following question:
Have repeatedly searched the web for the answer but could not find Anything. Did find this unanswered question however which is exactly what I have tried. So i thought id try here.
I have found a couple of ways of replacing text within an array, but can't get either of them to work. This would point to human error, but I can't see where I'm going wrong:
(1)
@config = map {s/oldtext/newtext/g; $_; } @config; for $t (0 .. $#config) { print"$config[$t][0]\n"; }
This doesn't produce the expected results though, as the oldtext remains and has not been changed at all.
(2) The 2nd approach I have tried is:
for (@config) {s/oldtext/newtext/g}
and when I print this out using the same bit of code as above, this doesn't work either.
So can somebody please tell me how I can replace text within an array (each element is a line of text)??? thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String substitution inside an array
by NetWallah (Canon) on Sep 09, 2011 at 04:42 UTC | |
by Monkomatic (Sexton) on Sep 09, 2011 at 05:51 UTC | |
by Monkomatic (Sexton) on Sep 09, 2011 at 05:57 UTC | |
|
Re: String substitution inside an array
by AnomalousMonk (Archbishop) on Sep 09, 2011 at 13:29 UTC |