#!/usr/bin/perl -w # 2000.10.13 altblue ## use strict; use File::Find; use Term::ANSIColor qw(:constants); my $filemask ='mp3'; $|=1; File::Find::finddepth({ wanted => \&process_file, no_chdir => 1 }, defined $ARGV[0] && -d $ARGV[0] ? $ARGV[0] : '.'); sub process_file { return unless /\.$filemask$/i; print BOLD CYAN $File::Find::name, RESET '('; my $fsize = -s $File::Find::name; print YELLOW commify($fsize), RESET 'bytes) ... '; my $operated = 0; stripBeginJunk($File::Find::name) and $operated=1, print BOLD YELLOW ' [stripped junk at the beginning] '; stripEndJunk($File::Find::name) and $operated=1, print BOLD YELLOW ' [stripped junk at the end] '; if($operated) { $fsize = -s $File::Find::name; print BOLD GREEN "OK (".commify($fsize).")", RESET $/; } else { print BOLD GREEN "Not Modified", RESET $/; } } sub stripBeginJunk { my $file = shift; local $/ = undef; open IN, $file or die "mujeR: $!\n"; seek(IN, 1, 0); my $content = ; my $pos = index ($content,'ÿû'); close IN; print $pos; if($pos>0) { my $out = substr($content,$pos); rename $file, "$file.bak" or die "error renaming $file: $!\n"; open OUT, ">$file" or die "cannot open $file for writing: $!\n"; print OUT $out; close OUT; return 1; } return 0; } sub stripEndJunk { return 0; } sub commify { $_ = reverse "@_"; s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; $_ = scalar reverse; } __END__ y