Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to replace a file extension 1

Status
Not open for further replies.

Haunter

Programmer
Jan 2, 2001
379
US
I have several image files that end in ".tga". they are used as source files for another program. I would like to display them in a table on a webpage. I think I need a regular expression to convert these endings. I have tried a few without success

$skin[$num]=~ s/.tga/.gif/;
or
$skin[$num]=~ tr/.tga/.gif/;

These filenames are listed in an array that is created like this
opendir(THISDIR, "$data_dir") or die "unable to open : $!";

@skin= readdir THISDIR;
close THISDIR;
My planned output is using a while statment to pass over the array. It works well but I was also wondering is there an easier way to slice an array?
 
Sorry I had a logic error,,,,I must read from Database file not Directory....

Ignore my last post on the Array issue,,,,

But will that regular expression work?
 
Use the s/ regex, not the tr/ one. I'm pretty sure that your tr/ regexp will do this:
*Replace all periods with a period (no change)
*replace all t's with g's
*Replace all g's with i's
*Replace all a's wth f's.

The s/ one will work fine.
 
Ty that worked fine with the t's, g's and a's but for some reason the period is giving it trouble.

I just omitted it as a serach and replace parameter and it served my purpose...

ty for the post
 
Sorry, I actually made a mistake. The period is a wildcard for ANY character. So if you want a physical period, then escape it: s/\.tga/\.gif/

Sorry for forgetting that ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top