A couple of things. Your method of passing arrays is
okay but could be troublesome if you've got big lists -
by doing: @newfiles = removenonmp3(@newfiles);
you 'flatten' @newfiles to a list, put it into the various
arrays @_, @args and the send it back as a list which
gets 'slurped' back into @newfiles. If you pass by
reference ("removenonmp3(\@newfiles)") you won't do
all that copying. For:@dirs = (@dirs, $Dateiname);
you should:push(@dirs, $Dateiname); Again,
it doesn't unravel/reravel (?) @dirs, just pushes the value
on the end. Add a 'closedir' for completeness.
Your shortenfilename could use a hash, something
like: my %oldfiles;
foreach $file (@FileArray){
if (length($file)>13){
$shortenedname = substr($file, 0, 8);
$shortenedname = $shortenedname.".mp3";
} else {$shortenedname = $file;}
if ( $oldfiles{$shortenedname}++ ) {
# short name already exist, try again
...
Using MS's idea of 6 and ~X, you could then: if ( $oldfiles{$shortenedname}++ ) {
my $base = substr($file, 0, 6);
my $test_shortenedname = 'not found';
for my $i ( 1 .. 9, a .. z ) {
$test_shortenedname = $base . '~' . $i;
unless $oldfiles{$test_shortenedname};
}
next if ($test_shortenedname eq 'not found');
# rather than die, just skip the bad/unshortenable name
$shortenedname = $test_shortenedname
}
push @short_files, $shortenedname;
}
return @short_files;
which it to also point out that shortenfilenames
seems to be returning the same array it gets, unchanged.
Change $file isn't going to modify the array members.
removemp, you probably want: if ($file =~ /\.mp3$/i ){
push(@mp3files, $file);
}
That is, you want only files that end in '.mp3', not
kiki_dee.mp3.tar.gz
I think you'll be clobbering your log file everytime,
as you're opening it in overwrite mode ('>eXpanium.log') each
time. There's something odd about redefining the log file
name in one sub and opening it in another. Log file names,
unless you're numbering them (logfile1.log, logfile2.log)
are probably better global. You pass @newfiles all
the time, except for rename, probably should be
consistent on that or just 'in-line' rename in main.
Just some suggestions, YM will always V ...
a |