On Dec 12, Mark Mclogan said:

>I want delete some lines of a file
>I  desire to erase the lines that contain the word " home "  since I can 
>make to eliminate these lines in the text if I have this word content in a 
>variable $var

The Perl FAQ (perldoc -q 'delete a line') suggests the following approach:

  {
    local $^I = ".bak";  # keeps a whatever.bak file for you
    local @ARGV = $filename;

    while (<>) {
      next if /$var/;  # skip this line if it matches /$var/
      print;
    }
  }

And that's that!  Perl takes care of the hard work for you.  And if $var
might have regex metacharacters in it (like * or |), you'll want to do

      next if /\Q$var\E/;

instead.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to