
Kanji
User
Sep 20, 2000, 10:45 PM
Post #2 of 4
(257 views)
|
|
Re: Using pattern matching to change a file extension?
[In reply to]
|
Can't Post
|
|
You should anchor your expression to the end of the string since that's all you need ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> /\.txt$/</pre><HR></BLOCKQUOTE> I add the \ before the . as . by itself will (usually) match any character, so \. will make sure you're only matching .txt and not atxt, xtxt, etc. Also, you can save yourself some effor and combine the s/// and if ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> if ( $files =~ s/\.txt$/.pr/ ) { push @lists, $files; }</pre><HR></BLOCKQUOTE> ... because s/// will return true if it was successful, and false otherwise.
|