MistaMuShu has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
Being completely new to Perl and regexps, I thought the best way to learn is to get some practice. I thought I was getting the hang of it with simpler searches so I tried to use it for a problem at work. Here's where I got stuck:
There are a series of folders and each folder is named like so: "6 digit number" "optional ." "optional 2 digit number" "optional letter"
i.e. ######, ######.##, or ######.##a
Inside each folder is a file with the same name as the folder plus "_vml_1.htm". i.e. 274813.99a_vml_1.htm and inside this file I want to find <foldername>_vml_1.emz and replace it with <foldername>_gif_1.gif
Here's a little test program
Please help shed some light on this so I don't have nightmares ;-)
Thanks in advance!
Jerry
Being completely new to Perl and regexps, I thought the best way to learn is to get some practice. I thought I was getting the hang of it with simpler searches so I tried to use it for a problem at work. Here's where I got stuck:
There are a series of folders and each folder is named like so: "6 digit number" "optional ." "optional 2 digit number" "optional letter"
i.e. ######, ######.##, or ######.##a
Inside each folder is a file with the same name as the folder plus "_vml_1.htm". i.e. 274813.99a_vml_1.htm and inside this file I want to find <foldername>_vml_1.emz and replace it with <foldername>_gif_1.gif
Here's a little test program
I realize I must be doing something really stupid when I try to match the foldername. But I can't figure out why the expression after \d{6} does not work.... $folder = shift(@dir); #dir is a listing of folders $folder =~ /(\d{6}.?\d{2}?\w?)/; open FILE, ">./$folder/$1_vml.htm"; ...
Please help shed some light on this so I don't have nightmares ;-)
Thanks in advance!
Jerry
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regular Expression Question
by Roy Johnson (Monsignor) on Jul 21, 2004 at 23:41 UTC | |
by MistaMuShu (Beadle) on Jul 22, 2004 at 19:02 UTC | |
Re: Regular Expression Question
by swkronenfeld (Hermit) on Jul 21, 2004 at 22:58 UTC | |
by MistaMuShu (Beadle) on Jul 22, 2004 at 19:00 UTC |
Back to
Seekers of Perl Wisdom