Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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.


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://1027208]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-28 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (256 votes), past polls