I threw together the following scriptlet to clean up some text files, but now I'd like to add 2 minor refinements.
- list the wah, blah, yada, and blankline regex's separately, like a config section. There's not necessarily 3, it varies from file to file.
- read infile and outfile names from STDIN
No doubt this is elementary to the many "real programmers" among the PM bretheren. The PM Tutorials suggest that a hash may do #1, but I'm at a loss on quite how to implement.
Thanks in advance for any direction or code examples.
cheers,
ybiC
#!/usr/bin/perl -w
use strict;
my $infile = "/dir/infilename";
my $outfile = "/dir/outfilename";
open (IN, "$infile") or die "Error opening $infile: $!\n";
open (OUT, ">$outfile") or die "Error opening $outfile: $!\n";
while (<IN>) {
s/wahwah//g; # unwanted text
s/blahblah//g; # more unwanted text
s/yadayada//g; # still more unwanted text
s/^\s+//g; # blank lines
print OUT $_ or die "Error writing to $outfile: $!\n";
}
close (IN) or die "Error closing $infile: $!\n";
close (OUT) or die "Error closing $outfile: $!\n";
# END
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.