As a style suggestion, I'd change process_files to use an argument hash. Simple to set up, and oh-so self-documenting. This would change
sub process_files { my ($function, $parm, $message, $extension, @list) = @_; ...
to
sub process_files { my ( $SubArgs ) = @_; my $function = $SubArgs->{ function } my $message = $SubArgs->{ message } my $parm = $SubArgs->{ parm } || ""; # If no parameter, def +ault to "". my $extension = $SubArgs->{ extension }; my @list = @{ $SubArgs->{ list } }; ...
The loop in process_files would change to be
foreach my $file (@list) { my $Newfile = substr($file, 0, 2); $Newfile = $Newfile . $extension; print "($function) $message $file to $Newfile\n"; @args = ("$function", "$parm", "$Newfile", "$file"); system(@args) == 0 or die "system @args failed: $?"; push @returnlist, $Newfile; }
Another note: I don't believe the double quotes are needed where you build your argument list.

So now your calls look like this:

# rename files to 01.mp3, 02.mp3, etc. my @mp3list = process_files( { function => "mv", message => "renaming", extension + => "\.mp3", list => @list } ); # call mpg123 to convert .mp3 to .wav my @wavlist = process_files( { function => "mpg123", param => "-qw", message => " +converting", extension => "\.wav", list => @mp3list } ); # call sox to convert each .wav to .cdr my @cdrlist = process_files( { function => "sox", message => "converting", extens +ion => "\.cdr", list => @wavlist } );
It might also be possible just to dump the parameter variable and use "mpg123 -qw" as the function you're running. It means your status message gets a little munged, but that makes the code a little simpler.

--t. alex

"Of course, you realize that this means war." -- Bugs Bunny.


In reply to Re: From MySQL MP3 Database to CD-R by talexb
in thread From MySQL MP3 Database to CD-R by shockme

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.