Syntactic Confectionery Delight | |
PerlMonks |
Re^2: Multiple / Mapping Search and Replaceby VinsWorldcom (Prior) |
on Apr 03, 2009 at 14:50 UTC ( [id://755289]=note: print w/replies, xml ) | Need Help?? |
It happens because the map file is read into a hash and normally there is no "order" to a hash. Thus, you can't guarantee that the search and replace will happen in the order you give in you map file. You're actually hitting this part of the code:
Stick in a helpful print to "debug" what's going on:
This is what we see using your input and mapping files:
You could maybe fix it by adding in Tie::Hash (I think) which is supposed to be able to order your hash. You would need to manipulate the hash variable %map when it is loaded at the beginning of the program. Unfortunately, I don't have the time now to code this up, but hey, my Perl code is "open source" :-) so have at it! UPDATE: If your infile is just the one column of words, call with: {C} > msar input.txt map.txt -r -i -c 1
UPDATE: MSAR.pl code now updated to use -w option which replaces on WHOLE WORDS only. Also, map.txt file will be read AND parsed AND used in search and replace in the order it is written (line 1, line 2 ... line n).
In Section
Code Catacombs
|
|