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

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 [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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027132]
[GotToBTru]: that is how this should have been done, no question
[GotToBTru]: probably back when there were 5 or so clauses

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-06-22 13:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (520 votes). Check out past polls.