regular expression for string substitution

D

Dave

I'm trying to use a rename perl script I found in a unix group and I
can't figure out the regular expression I'm supposed to pass it. I
have a file with the name index.cfm?id=6431.html and I want to make
the filename be index_6431.html. So, I thought it would be something
like s/.cfm?id=/_/ but that makes my file name become
_n_ex________6431_html. How can I make it replace the literal string
".cfm?id=" with the literal string "_"?

Thanks,
Dave
 
P

Paul Lalli

I'm trying to use a rename perl script I found in a unix group and I
can't figure out the regular expression I'm supposed to pass it. I
have a file with the name index.cfm?id=6431.html and I want to make
the filename be index_6431.html. So, I thought it would be something
like s/.cfm?id=/_/ but that makes my file name become
_n_ex________6431_html. How can I make it replace the literal string
".cfm?id=" with the literal string "_"?

Looking at your output, I'd have to guess you used the transliteration
operator tr/// or y/// rather than the substitute operator s///. Your
pattern is almost correct, but you need to escape the . and the ?.

$filename =~ s/\.cfm\?id=/_/;

If you're just passing the pattern to some other script, I'd suggest you
take a look at that script to see what it's doing. Again, it should be
using s///, not tr/// or y///

Paul Lalli
 
D

Dave

Paul,

Thanks for the input. I couldn't quite figure out what the script was
doing. It was a modified version of a script originally written by
Larry Wall so I just took Larry's original script and used that
instead. Escaping the . and ? worked great so now I am in business.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top