What do I need to do so that names with spaces also work? Any ideas?

The problem you're having is on the command line. When you do

mp3concat -s 700 `ls`
the results of ls become the command line for mp3concat, but if ls encounters filenames with embedded spaces, they'll appear as separate tokens on the command line. By the time these tokens get into @ARGV, it's too late.

One approach to fixing this is to have mp3concat take directory names as arguments (either instead of or in addition to filenames). Then, within the code, you could do something like

foreach my $arg ( @ARGV ) { doDir($arg), next if -d $arg; doFile($arg) if -f $arg; } ... sub doDir { my $dir = @_; opendir(D, $dir) or die "$dir: $!"; foreach my $file ( grep { -f } readdir(D) ) { doFile($file); } closedir(D); }
With a little more work, this can handle hierarchies, as well.

Another alternative is to use File::Find to traverse directories, looking for .mp3 files. If you search around the monastary, you'll find plenty of examples of using File::Find.


In reply to Re: filenames with spaces causing problems by dws
in thread filenames with spaces causing problems by drake50

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.