View Single Post
Old Nov 2nd, 2005, 6:06 PM   #5
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
        $filename=~ s/\//_/g; #replace all / with _
        $filename = reverse $filename; #reverse the file name so we can get rid of the leading _
        chop $filename; #get rid of the last _, which is really the first _
        $filename = reverse $filename; #get it back to the original filename, instead of backwards.

why?

        $filename=~ s/\//_/g; #replace all / with _
        $filename=~ s/^_//;   #replace the leading _

I don't like using chop because it just drops the last character ... it doesn't care if that character is actually what you wanted to drop ...

perldoc says: "It is much more efficient than 's/.$//s' because it neither scans nor copies the string."

but you reverse the string twice and I think that probably removes any advantage there may have been ...


Just a comment ... if you disagree, I'd liked to hear your reasoning for my own benefit ... I learn something new every day
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote