Hello Monks,
I have written this code sometime ago. Now it starts failing because it is not parsing correctly. It skips the accounts that is not supposed to print. However it doesn't print the complete numbers of lines which it needs to the output file. For example out of a file of 52 lines, let's say it is suppose to skip 10 (unwanted)lines and print 42(wanted) lines to an output file. It only prints 36 (wanted) lines. I don't understand why? Could you take a look at the script and let me know if there is anything that I need to do to correct the script. I was thinking in counting the number of lines then go line by line to move an unwanted account to another file. Could you give me an idea on how to accomplish it. Thank you in advance.
#!/usr/bin/perl -w
use strict;
my $infile = 'c:\\hl7file2.txt';
my ( $yr, $mo, $dy ) = (localtime)[5,4,3];
my $outfile = sprintf( "%04d%02d%02d.txt",$yr+1900,$mo+1,$dy );
my $counter;
open IN, "<$infile" or die "Couldn't open $infile, $!";
open OUT,">$outfile" or die "Couldn't open $outfile, $!";
$counter++;
print $counter;
my @finds = qw( 00000 00001 00002 00003 00004 76370 76375 76950 77403
+77404 77406
77407 77408 77409 77411 77412 77413 77414 77416 77418
+ 77370 77336
77417 );
my $finds_re = join '|', map { quotemeta }@finds;
$finds_re = qr/$finds_re/;
print $finds_re;
while(<IN>) {
next if m/$finds_re/;
print OUT;
}
close IN;
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.