Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to remove newline characters at the end of file

by trizen (Hermit)
on Feb 21, 2012 at 13:15 UTC ( #955303=note: print w/ replies, xml ) Need Help??


in reply to How to remove newline characters at the end of file

use Tie::File; foreach my $filename (grep { -f } @ARGV) { print "** Processing $filename\n"; tie my @file, 'Tie::File', $filename or die "Unable to tie: $!\n"; pop @file while $file[-1] eq q{}; untie @file or die "Unable to untie: $!\n"; print "** Done...\n\n"; }
You can specify multiple files as command line arguments.


Comment on Re: How to remove newline characters at the end of file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-07-04 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls