CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substitution problem

 



newera
Novice

Mar 24, 2005, 5:40 AM

Post #1 of 2 (232 views)
substitution problem Can't Post

Been trying to find this in my books, but no success......
I have some files I'm trying to rename at the beginning of the filename. 4,200 of them.
This expression will do the ones that have 2 characters in front of the _ , but how can I also change ones that have 3 characters in front of the _ at the same time?

$filetable = "$artist_ids[0]";
$filetable2 = $filetable.'_';
$filename =~ s/.._/$filetable2/i;

Sample filenames are:
an_a_tire_d_aile.mp3
tob_qui_detient_le_secret.mp3

It changes the one with an_ , but not the one with tob_

I know it must be something simple? :)


newera
Novice

Mar 24, 2005, 8:58 AM

Post #2 of 2 (228 views)
Re: [newera] substitution problem [In reply to] Can't Post

Figured it out.....
I just split the filenames with the _ and replaced the first section with the new chars.

$old_filename = $filename;

@songs = split(/_/, $old_filename);
$first = "$songs[0]";

$filename =~ s/$first/$filetable/i;

rename("/var/www/wmmw/vc2/$filetable/$old_filename", "/var/www/wmmw/vc2/$filetable/$filename");

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives