astroid96 has asked for the wisdom of the Perl Monks concerning the following question:
what i'm trying to do is read the file and replace the array index numbers with random numbers, so far here is what i've come up with:@a = ("'hello world'",'print ', ';'); eval(@a[1] . @a[0] . @a[2]);
the problem is this only replaces the first array found "@a1" the others and untouched.. why is this? :/ thanks$re='.*?(@)((?:[a-z][a-z0-9_]*))(\\[)(\\d+)(\\])'; open(FILE, "+<ibank.txt"); @code = <FILE>; close FILE; foreach (@code) { $code .= $_; if ($_ =~ m/$re/) { $rndIndex=0; $c1=$1;$var1=$2;$index=$4;$c3=$5; $rndIndex = int(rand(99999)); $old = $c1.$var1.$index.$c3; $varName = "$index$c3"; $varName =~ s/$index/$rndIndex/; $code =~ s/[$old]/$varName/g; } } print $code; #show output example
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replace arrays in external file
by CountZero (Bishop) on Apr 10, 2012 at 15:30 UTC | |
by astroid96 (Initiate) on Apr 10, 2012 at 16:15 UTC | |
by CountZero (Bishop) on Apr 10, 2012 at 20:18 UTC | |
|
Re: Replace arrays in external file
by brx (Pilgrim) on Apr 10, 2012 at 14:54 UTC |