Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just a few comments (I know it's a little late but hopefully adds more clarity).

Firstly, once you read in a line from oldfile you need to keep it somewhere to check it against $valueToDelete. There are many ways to do this. These include putting each line into an array or even a hash etc.

Secondly, does newfile have anything in it..? if you are appending to newfile your open should look like

open my $ff, ">>newfile" or die "open failed: $!\n";
or if you are creating newfile from scratch, your open should look like
open my $ff, ">newfile" or die "open failed: $!\n";
Also if you are creating the file there will be nothing in it to read so you don't need to do the while loop or the chomp. You can simply do the print if the value you want to print is not like the $valueToDelete. Should you choose to put the lines from oldfile into an array your code would look something like
foreach my $line (@oldlines) { unless ($line eq $valueToDelete) { print $ff "$line\n"; } }
Another quick note is that when you are printing to newfile you must use your filehandle $ff.
-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: deleting lines from file by AcidHawk
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found