in reply to Re: Same problem replacing array index numbers
in thread Same problem replacing array index numbers
Fixed issues of producing something like this:my $s = 'xx @ra[1] y @ara[23] z @ra[1] aa @ara[23] b @ra[1] @ara[23]'; print qq{'$s'\n}; my %found; my %generated; $s =~ s{ \@ ([a-z] [a-z\d_]* \[) \K (\d+) (?= \]) } { $found{"$1$2"} //= do { my $rand; do {$rand = int rand 9999} while exists $generated{$rand}; $generated{$rand} = (); $rand; }; }xmsge; print qq{'$s'\n};
'xx @ra[1] y @ara[23] z @ra[1] aa @ara[23] b @ra[1] @ara[23]' 'xx @ra[1] y @ara[0] z @ra[1] aa @ara[2] b @ra[1] @ara[2]'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Same problem replacing array index numbers
by AnomalousMonk (Archbishop) on Apr 11, 2012 at 21:27 UTC | |
|
Re^3: Same problem replacing array index numbers
by Anonymous Monk on Apr 12, 2012 at 03:49 UTC |