in reply to Re^4: using hashes
in thread iterating hash keys?
That will require that either side of your key must correspond to the start or finish of the line, or to the pattern \w\W or \W\w.s/\b$find\b/$replace/g
If you can't use word boundaries to delimit, you could try your keys in descending key length.
for my $line (@lines) { for my $find(sort {length($b) <=> length($a)} keys %ids) { $line =~ s/$find/$ids{$find}/g; } }
This still has some potential for key overlap, but we'd really need to see you real data to design the correct regex for it. There are a number of ways to cut this up, the choosing the 'right' answer depends strongly on actual input.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: using hashes
by R56 (Sexton) on Sep 26, 2013 at 18:16 UTC | |
|
Re^6: using hashes
by R56 (Sexton) on Sep 27, 2013 at 13:26 UTC | |
by kennethk (Abbot) on Sep 27, 2013 at 15:41 UTC | |
by R56 (Sexton) on Sep 27, 2013 at 17:48 UTC | |
by kennethk (Abbot) on Sep 27, 2013 at 21:26 UTC | |
by R56 (Sexton) on Sep 27, 2013 at 22:36 UTC |