Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
ie. so if my codes are $code[0]=ABC and $code[1]=DEF and the file contains the text ABC and DEF it gets replaced with the numbers 0 and 1 instead.
I have tried this:
Which doesn't work. I'm probably trying something really dumb, but I hoped the substitution might be able to work like that. Any ideas on better methods ?while(<DATA>) { for($a=0;$a scalar@codes;$a++) { s/$codes[$a]/$a/; } } print $_;
Thanks a lot,
anon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match text in file with array and substitute array position ?
by chromatic (Archbishop) on Nov 29, 2002 at 19:14 UTC | |
|
Re: Match text in file with array and substitute array position ?
by arturo (Vicar) on Nov 29, 2002 at 17:42 UTC | |
|
Re: Match text in file with array and substitute array position ?
by John M. Dlugosz (Monsignor) on Nov 29, 2002 at 17:44 UTC |