Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

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

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 perusing the Monastery: (5)
As of 2016-08-31 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (436 votes). Check out past polls.