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

Re: Delete specific lines from txt file.

by trizen (Hermit)
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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2015-11-30 00:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (755 votes), past polls