CoderZone.org

Category: >> Perl Code >> Basename And Dirname in Perl Bookmark and Share

<< lastnext >>

Snippet Name: Basename And Dirname in Perl

Description: These two Perl functions implement approximations of the UNIX utilities 'basename' and 'dirname', though basename() automatically strips off the last extension no matter what.

Also see:

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: December 03rd, 2010

sub basename($) {
 my $file = shift;
 $file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!;
 return $file;
}
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 11