You should be able to do it if you're working with plain text files. Still, your description doesn't really say what you want to do in specific terms. Just that you're searching and replacing.
So, here's a few quick observations:
@newrecords = (@newrecords,"$name");
Could be replaced with:
push(@newrecords, $name);
Apart from that, you seem to have the right idea. Just make sure your substitution table doesn't contain any "fancy" characters such as brackets or question marks and so forth. If it might, probably best to handle them better:
$name =~ s/\s\Q$key\E/$value/ig;
The \Q and \E prevent any of those characters from being treated as special. If you had a $key of 'OPEN?' then it would match both 'OPE' and 'OPEN' which is clearly not what you want. Also, if you are matching words, this is probably a better regex:
$name =~ s/\b\Q$key\E\b/$value/ig;
The \b means to match on a word boundary. This way you can replace things like the "HAM" in "RALPH USED A HAM AS A HAMMER" without substituting on "HAMMER".
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.