Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Delete strings

by almut (Canon)
on Apr 10, 2009 at 08:09 UTC ( #756768=note: print w/replies, xml ) Need Help??

in reply to Delete strings

perl -i -ne 'print if $end_del ||= /1\.0/' file

/1\.0/ does a substring match; if you want to stop deleting only when the line contains nothing but "1.0", either use /^1\.0$/, or $_ eq "1.0\n".

Replies are listed 'Best First'.
Re^2: Delete strings
by jwkrahn (Monsignor) on Apr 10, 2009 at 16:00 UTC

    Another way to do that:

    perl -i -ne 'print if /1\.0/ .. eof' file
Re^2: Delete strings
by zashwing (Initiate) on Apr 10, 2009 at 15:51 UTC
    What's with the idea you have to write the solution in a single line of code?
    This can be done easily with a few lines of code, why write it in a single line? Are you running with 8MB of ram or something?
    1. Open the file IO in read write mode.
    2. Read the file into an array.
    3. Set up a good old fashioned boolean $foundString
    4. Traverse the array til the boolean is true printing stuff to the file.
    5. Boolean is true close the file..DONE.
      ... why write it in a single line?

      Why not?  I never said you have to... Feel free to write as many lines as makes you feel comfortable.  I just happen to like one-liners for tasks like these — which doesn't imply anyone else would have to like or use them, too.  Yet others like golfing. Just for the fun of it...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://756768]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2023-11-30 04:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found