Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 chanting in the Monastery: (10)
As of 2014-12-21 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls