ccdoub has asked for the wisdom of the Perl Monks concerning the following question:
I have this cute little console app called renamer, where i give a string (pattern) as fisrt argument and another string as secong argument, then the app replace all file names matches with the new string. I use it to rename music files.
I'll put it with my spanish comments.
# Open the current dir opendir (INPUT, "."); # Asigna el contenido del HANDLE # a un arreglo @files = readdir INPUT; # Itera sobre los archivos foreach $item (@files) { # Verifica la coincidencia # de la regexp de busqueda # en el archivo iterado if ($item =~ m/$ARGV[0]/) { # Respalda el archivo original $image = $item; # Reemplaza la coincidencia # con le string del segundo # parametro $item =~ s/$ARGV[0]/$ARGV[1]/g; # Renombra el archivo rename($image, $item) or warn "Couldn't rename $file to $item: $!\n"; } }
And does't work with patters (string) with special characters.
Is there a function that translate a string in his pattern equivalence?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert a string in his pattern equivalence
by suhailck (Friar) on Sep 20, 2010 at 01:47 UTC | |
by ccdoub (Initiate) on Sep 20, 2010 at 02:49 UTC | |
by ccdoub (Initiate) on Sep 20, 2010 at 23:51 UTC |