in reply to Rewrite a PHP fileExtension function

sub fileExtension { my $file = shift; my $pos = index($file,"."); if ($pos == "0") { return undef; } else { my $ext = lc(substr($file,$pos)); return $ext; } } my $filename = 'test.test.txt'; print fileExtension($filename);
prints ".test.txt". So I don't think I'd recommend that one...


($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re^2: Rewrite a PHP fileExtension function
by revdiablo (Prior) on Sep 09, 2005 at 16:27 UTC

    For what it's worth, this bug is not present in the PHP version. It uses strrpos, which would be rindex in Perl-speak.

Re^2: Rewrite a PHP fileExtension function
by ghenry (Vicar) on Sep 09, 2005 at 07:16 UTC

    Yeah, wouldn't work with a file.tar.gz

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!