in reply to Re: getting the tail of a string
in thread getting the tail of a string
I wouldn't say that split and or regexp are the most general ways of attacking this problem. The most general (read: efficient) way would be to find the character with rindex and extract the end of the string with substr. The following does the trick:
my $ext = substr($x, rindex($x,'.')+1);This happens to rely on a side-effect of rindex, which is that if the character sought for is not found in the string, -1 is returned. Add 1 (pedant note: length('.') in fact), and instead of stepping over the sought character, it brings -1 up to 0, and hence your substr will hand you back the whole string. This can be construed as a feature :)
But yes, File::Basename is the way to go in this particular case.
update: weird transcription error spotted by sauoq: I had -rindex instead of rindex. Curiously enough, that's exactly what I had when I checked the snippet out on the command line. That'll teach me not to cut and paste...
_____________________________________________
Come to YAPC::Europe 2003 in Paris, 23-25 July 2003.
|
|---|