Dear Master Monks,
Would you rewrite:
As:function fileExtension($file) { $pos = strrpos($file,"."); if ($pos == "0") return false; else { $ext = strtolower(substr($file,$pos)); return $ext; } }
Or (as per the Cookbook, File::Basename):sub fileExtension { my $file = shift; my $pos = index($file,"."); if ($pos == "0") { return undef; } else { my $ext = lc(substr($file,$pos)); return $ext; } }
sub extension { my $path = shift; my $ext = (fileparse($path,'\.[^.]*'))[2]; $ext =~ s/^\.//; return $ext; }
I think the Cookbook is the best.
Gavin.
In reply to Rewrite a PHP fileExtension function by ghenry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |