Hi all.

I've got the following code to standarize my movie titles:

#!/usr/bin/perl use strict; use warnings; for (<@ARGV>) { # Change spaces to _ my $new = $_; $new =~ s/\s/_/g; rename($_, $new) or die "Cannot rename '$_' to '$new': $!"; # Capitalize my $new2 = $new; $new2 =~ s/(^|_)(\w)/$1\U$2/g; print "$_ -> $new2\n"; rename($new, $new2) or die "Cannot rename '$new' to '$new2': $!"; }

The problem is exactly because the files have spaces in the name. I've searched for a solution and I only find that I have to quote the argument; this partially works, as it works if I use something like titulize.pl "*.avi", but not if I use titulize.pl "test spacefull name.avi". Moreover, I'd like if possible to pass the file names as in the normal way, as every other command line program.

Could somebody bring me some light about how to pass file names with spaces as arguments?

Best regards.

Update: Excuse me all of you who have send me your ideas; I'm having some problems with my computer, so I will answer all of you as soon as I could try your solutions.


In reply to Spaces in file names passed as arguments by txixco

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.