Your problem is that you cannot just edit a file in place. All you are changing is the line which is in a variable in memory, it never gets to the disk. The most concise way to do this is to open the file, and then print out all the lines except the one you don't want. Then you can redirect the output to another file. Also, some of perl's command-line arguments can help you accomplish that:

#!/usr/bin/perl -nw use strict print unless /$var/i; # or a perl one-liner perl -i.bak -nwe 'print unless /019/i' <file>

HTH

Addendum: RE: Abigail's comments: Added the -e switch. And the 'gi' is just following the orginal poster since 019 may not be the only data (s)he is looking for, didn't want the confuse the issue if they plugged in some other data and it was missing. I suppose the 'g' is superfluous in this case, guess you can safely remove that one.


In reply to Re: Deleting a line out of text file by pzbagel
in thread Deleting a line out of text file by Anonymous Monk

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.