Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: eXpanium file converter

by a (Friar)
on Feb 20, 2001 at 09:40 UTC ( [id://59583]=note: print w/replies, xml ) Need Help??


in reply to eXpanium file converter

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

Replies are listed 'Best First'.
Re: Re: eXpanium file converter
by C-Keen (Monk) on Feb 20, 2001 at 13:17 UTC
    Thank you I will look into it and post the new code with the next version which will include a recover mode so that you can redo the renaming. This would make it easy to use the more descriptive filenames e.g. when writing the files back from a cd-rom.

    But I think just skipping a filename would mess up my list which has to be in the same order as the list with the original names doesn't it? I like the idea of the ~X method though. Thank you very much

    C-Keen

      Well, perhaps ... you could do something so you remove the "unshortenable" name from the list (a decent error msg "can not shorten $file" ('nicht canst ger-shorten' ;-)) too. Just seems a shame to quit the whole mess if only one file can't be handled.

      a

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found