in reply to Supress a line every time it finds a string
Improv makes some valid points, I'll render them down to - 'This code is difficult to interpret' , by humans and perl alike it would seem.
So lets, get forensic on it. You initialising some funky stuff here, some of it looks like you plan to add to it later.
#!perl -w use strict; my $buffer=""; my $suppress = 0; my @field; my %newline; $newline{$_} = 1 for qw(MSH); my %skipaccount; $skipaccount{$_} = 1 for qw(77403 77404 77406 77407 77408 77409 77411 +77412 77413 77414 77416 77418); my $infile = 'c:/rx_q.008'; my $outfile = 'c:/ftpscript/idxfile.txt'; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while (<IN>) {
# Ok now $_ has scalar input from <IN>
chomp();
# and it's newline chomped # here is where it is confusing, there is nothing in @field, # let alone at $field[0] , do you mean to split up $_ into @field ???
if ($newline{$field[0]}) { processbuffer(); }
# OK , I am certain this is not doing what you expect #if ( index($newline{$_}, $skipaccount{$_}) != -1) { # $suppress = 1 if $skipaccount{$field[7]}; #} # What you're aiming at (IMHO) is to set suppress to 1 if # the item at index 7 in your fields array (which is split from $_ ri +ght??) # is a member of the skipaccount hash. # the if (index($newline{$_} ) makes no sense to me, not in the least + with # the data that appears to be in those objects.
$buffer .= "$_\n"; } # Personally I prefer calling functions like this with an arg, rather +than # relying on a globar ($buffer in this case). processbuffer(); sub processbuffer { print OUT $buffer unless $suppress; $buffer=""; $suppress = 0; }
|
|---|