It's unclear what "newfile" should contain. If you want it to have
one 111 ury
th  ese  ll
in it, thenyour program makes absolutely no sense. Since this smells like homework, here are some questions I am asking myself, and then a proposed solution that the prof probably won't accept ;) :
  1. Why are you counting occurances or existance of the lines in oldfile? How does this advance your aims to delete a line?
  2. Why are you printing the number of times oldfile has a certain line to the standard output. This makes little sense to me.
And, to wrap it up, a solution for inplace editing (this is as per what you seem to be asking.):
#!/usr/bin/perl use strict; use warnings; use Tie::File; my $value_to_delete = <STDIN>; chomp $value_to_delete; tie my @file, 'Tie::File', "file" or die "Couldn't open: $!"; @file = grep { $_ ne $value_to_delete } @file; untie @file;
N.B. This solution is quite cost effective memory-wise, because Tie::File does some cool behind-the-scenes stuff so you don't have to read everything in at once. This is huge if the file is very large.

UPDATE: Here's a non-in place solution:
#!/usr/bin/perl -pi.orig BEGIN {$value_to_delete = <STDIN>} undef $_ if $_ eq $value_to_delete;



Code is (almost) always untested.
http://www.justicepoetic.net/

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