Created
August 3, 2012 09:18
-
-
Save vStone/3246220 to your computer and use it in GitHub Desktop.
Perl script to strip newline at end of files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
## Strips the newline from the end of a file. | |
# This is important because we cant have newlines after the pw hash. | |
# Run this on a file before committing. | |
use autodie qw(open sysseek sysread truncate); | |
my $file = shift; | |
open my $fh, '+>>', $file; | |
my $pos = tell $fh; | |
sysseek $fh, $pos - 1, 0; | |
sysread $fh, my $buf, 1 or die 'No data to read?'; | |
if($buf eq "\n"){ | |
truncate $fh, $pos - 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's wrong with chomp ?