Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I need to remove entries in a txt file. The entries to remove, must start with a pattern /phn/ then end on /1ord/. e.g
# input phn .. .. # 1ord
Used the following:
if (/phn_a/ ... /1ord/) { print OUT $_; }
But this prints out the first finding of phna_ through to first 1ord. 5 lines separate these patterns in the text file Tried this also, but this seems to starts printing from a poisiton i dont expect it to:
$nLines = 5 if ( /1ord$/ ); print OUT if $nLines-- > 0;

Replies are listed 'Best First'.
Re: extracting lines
by neniro (Priest) on Jul 02, 2004 at 10:38 UTC
    Try unless instead of if.
    print OUT unless (/phn_a/ .. /1ord/);
    UPDATE: more detailed:
    #!/usr/bin/perl use strict; use warnings; while (<DATA>) { print unless (/phn/ .. /1ord/); } __DATA__ black # input phn blue red green # 1ord yellow white
      this appears to print everything in the file, no change
        sorry just seen the update