Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Delete specific lines from txt file.

by trizen (Friar)
on Aug 07, 2012 at 07:35 UTC ( #985902=note: print w/ replies, xml ) Need Help??


in reply to Delete specific lines from txt file.

See perldoc Tie::File.

Here is a sample code:

use strict; use warnings; use Tie::File; my $filename = '/path/to/file.txt'; my $firstname = 'John'; my $lastname = 'Watter'; tie my @array, 'Tie::File', $filename or die $!; for(my $i = 0; $i <= $#array; $i++){ if($array[$i] =~ /\b$firstname\b.+\b$lastname\b/){ splice(@array, --$i, 5); } } untie @array;


Comment on Re: Delete specific lines from txt file.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-08-21 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls