Please use strict and warnings. Please do not use a filehandle called true, then have a while (<true>) that will go false. That hurt my head ;)

It is good practice to test the result of attempts to open a file, and polite to close them when you have finished reading from them.

perltidy is your friend

The three argument form of open is safer

update

Added a check that there is something remaining in the original file while editing
#!/usr/bin/perl use strict; use warnings; # true was a confusing name open ORIG, "<", "ORIGINAL" or die "probs: ORIGINAL : $!\n"; open EDIT, "<", "cut_out" or die "probs: cut_out2 : $!\n"; open REST, ">", "REST" or die "probs: REST : $!\n"; while (<EDIT>) { chomp; my $j = $_; print "grabbing $j lines to $.out.test\n"; open OUT, ">", "$.out.test" or die "can not open $.out.test : $!\n +"; while ($j--){ if (my $line = <ORIG>) { print OUT $line; } else { die "Ran out of input file before editing complete !\n"; } } close OUT; } close EDIT; while (<ORIG>) { print REST; } close ORIG; close REST; # rename ("REST", "COMPARE");

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re: removing lines from a file by Random_Walk
in thread removing lines from a 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.