Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: removing lines that are in the end of a file

by trizen (Friar)
on Apr 05, 2013 at 12:21 UTC ( #1027132=note: print w/ replies, xml ) Need Help??


in reply to removing lines that are in the end of a file

Is this what you are looking for?

use strict; use warnings; use Tie::File; # usage: perl script.pl [file1] [file2] [...] foreach my $file (grep { -f } @ARGV) { tie my @file, 'Tie::File', $file or die "Can't tie into file $file: $!"; my $regex = qr/\sSIL\s*\z/; foreach my $i (reverse 0 .. $#file) { if ($file[$i] =~ /$regex/) { 1 while ($file[--$i] =~ /$regex/); print "$file[$i + 1]\n"; $#file = $i + 1; last; } } untie @file; }


Comment on Re: removing lines that are in the end of a file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-08-22 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (145 votes), past polls