ghenry has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Rewrite a PHP fileExtension function
by Cody Pendant (Prior) on Sep 09, 2005 at 06:56 UTC | |
by revdiablo (Prior) on Sep 09, 2005 at 16:27 UTC | |
by ghenry (Vicar) on Sep 09, 2005 at 07:16 UTC | |
|
Re: Rewrite a PHP fileExtension function
by Tanktalus (Canon) on Sep 09, 2005 at 14:17 UTC | |
|
Re: Rewrite a PHP fileExtension function
by sasikumar (Monk) on Sep 09, 2005 at 06:21 UTC | |
|
Re: Rewrite a PHP fileExtension function
by revdiablo (Prior) on Sep 09, 2005 at 16:30 UTC |