Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use rindex to eliminate loop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use rindex to eliminate loop
Authored by: houchin on Oct 19, '01 01:34:21PM

Great idea!

To improve the script, why don't you just use rindex to get the last period, instead
of looping through the filename. Also, you should probably verify that the files
does have an extension. Here's some code to replace the while loop at the beginning:

$start = rindex($file, ".");
die "Unknown file extension: $file\n" if ($start == -1);
$ext = substr($file,$start + 1);

(due to problems with backslashes in comments, make sure it's $file[backslash]n in the die statement



[ Reply to This | # ]
Use rindex to eliminate loop
Authored by: eagle on Oct 20, '01 02:48:35PM

Thanks for the suggestion. I didn't know about rindex(). I have changed my code per your recommendation.



[ Reply to This | # ]