Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by gsiems (Chaplain)
on Apr 05, 2013 at 19:40 UTC ( #1027208=note: print w/replies, xml ) Need Help??


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

Another approach using split and join:
#!/usr/bin/env perl use strict; use warnings; foreach my $file (grep { -f } @ARGV) { my $data = slurp_file ($file); my $new_data = join ('', (split /(SIL\n)/, $data, 5)[ 0 .. 3 ]); open my $OUT, '>', $file or die $!; print $OUT $new_data; close $OUT; } sub slurp_file { local (*ARGV, $/); @ARGV = shift; <> }

Update

This only works if there are no additional SIL lines interspersed between the first line and the SILL lines at the end.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2016-09-28 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (523 votes). Check out past polls.