in reply to Re: Finding a string within a string
in thread Finding a string within a string

Tachyon I appreciate your help. Here is my code. This code only suppresses a block, how could I modify this code to instead of suppressing a block it suppress a line. Here is the code:
#!perl -w my ($fs, $cs, $rs, $ec, $ss); setdelimiters('|^~\&'); sub setdelimiters { ($fs, $cs, $rs, $ec, $ss) = map {quotemeta} split //, $_[0]; } use strict; my $buffer=""; my $suppress = 0; my @field; my %newblock; my %partofblock; my %skipaccount; $skipaccount{$_} = 1 for qw(77403 77404 77406 77407 77408 77409 77411 +77412 77413 77414 77416 77418); my $infile = 'c:/testfile.txt'; my $outfile = 'c:/idxfile.txt'; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; $newblock{$_} = 1 for qw(MSH); $partofblock{$_} = 1 for qw(EVN PID FT1); while (<IN>) { chomp(); if (/^(MSH)(.....)/) { setdelimiters($2); } @field = split /$fs/; if ($newblock{$field[0]}) { processbuffer(); } elsif (!$partofblock{$field[0]}) { print STDERR "Possible error: segment=$field[0] line $.\n"; } if ($field[0] eq "FT1") { $suppress = 1 if $skipaccount{$field[7]}; } $buffer .= "$_\n"; } processbuffer(); sub processbuffer { print OUT $buffer unless $suppress; $buffer=""; $suppress = 0; }

Replies are listed 'Best First'.
Re: Re: Re: Finding a string within a string
by tachyon (Chancellor) on Apr 10, 2003 at 05:20 UTC
    perl -n -e "m/77403|77404|77406|77407|77408|77409|77411|77412|77413|77 +414|77416|77418/ or print" infile.txt > outfile.txt

    Otherwise you will need to be more exact ie specify what the data looks like and what your code is supposed to do. It is far from clear in what you asked and the code you posted :-)

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Re: Finding a string within a string
by Juerd (Abbot) on Apr 10, 2003 at 06:32 UTC

    Is there any logic to your indentation style, or do you just hit tab at random? :)

    Consistent indentation makes code much easier to read. If code is easy to read, you'll get more useful answers because more people will bother to try to understand.

    Juerd
    - http://juerd.nl/
    - spamcollector_perlmonks@juerd.nl (do not use).