Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re:^4 Deleting a line out of text file

by kesterkester (Hermit)
on Aug 13, 2003 at 19:03 UTC ( [id://283659]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Deleting a line out of text file
in thread Deleting a line out of text file

Here's another way, using grep to exclude lines matching the unwanted pattern as they are read in from the file:
... use strict; my $file = 'data_file.txt'; my $bad_pattern = '019'; open my $in_fh, "<$file" or die "can't open $file to read"; my @good_lines = grep { !/$bad_pattern/ } <$in_fh>; close $in_fh; open my $out_fh, ">$file" or die "can't open $file to write"; print $out_fh $_ foreach @good_lines; close $out_fh;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found