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


In reply to Re: eXpanium file converter by a
in thread eXpanium file converter by C-Keen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.