remove_eof_newlines.pl 472 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Remove newline characters from the end of files
  4. # WARNING: No backup files are created!
  5. use strict;
  6. use warnings;
  7. use Tie::File;
  8. foreach my $filename (grep { -f } @ARGV) {
  9. print "** Processing $filename\n";
  10. tie my @file, 'Tie::File', $filename
  11. or die "Unable to tie: $!\n";
  12. pop @file while $file[-1] eq q{};
  13. untie @file
  14. or die "Unable to untie: $!\n";
  15. print "** Done.\n\n";
  16. }