txixco has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Spaces in file names passed as arguments
by toolic (Bishop) on Sep 08, 2011 at 15:55 UTC | |
by txixco (Novice) on Sep 10, 2011 at 05:07 UTC | |
|
Re: Spaces in file names passed as arguments
by Utilitarian (Vicar) on Sep 08, 2011 at 15:50 UTC | |
|
Re: Spaces in file names passed as arguments
by aaron_baugher (Curate) on Sep 08, 2011 at 16:00 UTC | |
by Anonymous Monk on Sep 08, 2011 at 18:04 UTC |