in reply to Rewrite a PHP fileExtension function
The cookbook version is better, but I'm not sure I'd like to load File::Basename just for this. I'd probably end up writing it as:
sub extension { my $path = shift; my $ext = (split /\./, $path)[-1]; return $ext; }
Update: and since we all know this is going to devolve into Golf sooner or later, here's a shortened version of that:
sub extension { (split/\./,$_[0])[-1]; }
|
|---|