Hello Monks, I'm trying to troubleshoot this code that is suppose to supress a line once it finds a string within a string. I would use regex pattern but I prefer to use INDEX unless if there is a perfect way to use it in the code. I tried to read the file with the script but it keeps failing with "Use of uninitialized value" I'll appreicate if you could let me knowhwat I need to chnagei the code to make it work. Thanks in advance.
#!perl -w use strict; my $buffer=""; my $suppress = 0; my @field; my %newline; # my %partofblock; 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, $!"; $newline{$_} = 1 for qw(MSH); while (<IN>) { chomp(); if ($newline{$field[0]}) { processbuffer(); } if ( index($newline{$_}, $skipaccount{$_}) != -1) { $suppress = 1 if $skipaccount{$field[7]}; } $buffer .= "$_\n"; } processbuffer(); sub processbuffer { print OUT $buffer unless $suppress; $buffer=""; $suppress = 0; }

In reply to Supress a line every time it finds a string by Skyler99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.