Hellow fellow monks,
I wrote a code to update names of variables in another code to follow a new naming rules. It does:
read in a mapping table
read in an input file;
replace some variable names with new ones (regex);
write it to an input file;
The code looks like:
open(MAP, "<$new_name_map_file");
while (<MAP>) {
chomp;
tr/A-Z/a-z/;
@map_line = split (/\t/);
$mapper{$map_line[0]} = $map_line[1];
}
close(MAP);
open(IN, "<input_file");
open(OUT, ">input_file.new");
while (<IN>) {
print "%";
tr/A-Z/a-z/;
foreach $key (sort keys %mapper) {
s/\b$key\b/$mapper{$key}/g;
}
print OUT "$_";
}
close(IN);
clse(OUT);
I have ~15000 lines in the input file and ~8000 lines(entries) in the new naming mapping file. My script runs hours to finish it. Please let me know if you know better way to speed the code up. Please assume I can't buy any hardware:-(
From a poor monk.
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.