astroid96 has asked for the wisdom of the Perl Monks concerning the following question:
all of the arrays matching the exact one found should be replaced, eg: @array123 @array123 @array1234 @array1234 could be: @array6677 @array6677 @array8686 @array8686 thanks!$re='.*?(@)((?:[a-z][a-z0-9_]*))(\\[)(\\d+)(\\])'; #find arrays e.g: @ +arry[123] open(FILE, "+<", "xxxxx.pl"); @code = <FILE>; close FILE; $code = join ("",@code); foreach (@code) { if($_ =~ m/$re/) { #check if this line contains any array my $random_number = int(rand(9999)); #create a new index +for that array $OldVariable = $1.$2.$3.$4.$5; #store the old array + in variable $NewVariable = $1.$2.$3.$random_number.$5; #changing the index +in the found array $code =~ s/$OldVariable/$NewVariable/g; #now replace all of +that found array with the new one. } } print $code; <>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Same problem replacing array index numbers
by JavaFan (Canon) on Apr 11, 2012 at 14:49 UTC | |
by astroid96 (Initiate) on Apr 11, 2012 at 15:03 UTC | |
|
Re: Same problem replacing array index numbers
by AnomalousMonk (Archbishop) on Apr 11, 2012 at 15:45 UTC | |
by Anonymous Monk on Apr 11, 2012 at 18:10 UTC | |
by AnomalousMonk (Archbishop) on Apr 11, 2012 at 21:27 UTC | |
by Anonymous Monk on Apr 12, 2012 at 03:49 UTC |