Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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; <> }


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027208]
[1nickt]: I know what I believe and whether I have integrity. My actions will speak more.
[karlgoethebier]: choroba Nothing unclever in my sig. And remember: Beeing too clever is a bad mistake ;-)
[1nickt]: This is not to suggest that Karl should remove his slogan. Just thoughts of mine... Trust me I believe I am very much more radical than most, and if I had a slogan for every gross injustice in my sig, there would be no more bytes!
Discipulus redskins .. well native american..
[1nickt]: So if I was to offer any editorial advice it would be to (1) make it endure time passing (2) make it positive (3) make it about you and your beliefs
[1nickt]: (Disicpulus The new best choice is maybe "First People"
[karlgoethebier]: Discipulus: This is called "Volksverhetzung" in German which means
[karlgoethebier]: incitement of the people and it is prohibited by law
[1nickt]: The best sign I have sign in a protest march was carried by a kid of about 10 years "If you build a wall my generation will tear it down."
[1nickt]: ... sign I have seen ...

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

    Results (519 votes). Check out past polls.