basename02.pl to HTML.

index -|- end

Generated: Tue Feb 2 17:54:22 2010 from basename02.pl 2007/03/31 935.

#!/perl -w
# NAME: basename02.pl
# AIM: simple example of using fileparse, and basename ...
# see http://perldoc.perl.org/File/Basename.html
use strict;
use warnings;
use File::Basename;
use File::Spec::Functions qw[splitpath canonpath splitdir abs2rel];
my $fullname = 'C:\path1\path2\basename.txt';
show_split( $fullname );
$fullname = 'C:\path1/path2/somename.html'; # mixed unix windows spearator
show_split( $fullname );
$fullname = '..\..\relname.c'; # simple relative path
show_split( $fullname );
$fullname = 'C:\path1\path2\./relname2'; # without ext
show_split( $fullname );
exit(0);
# subs
sub show_split {
   my ($fil) = shift;
   my ($name,$path,$suffix) = fileparse( $fil, qr/\.[^.]*/ );
   print "name=[$name], path=[$path], suffix=[$suffix] ... \n";
   my ($volume, $dir_path, $file) = splitpath( $fil );
   print "volume=[$volume], path=[$dir_path], file=[$file] ... \n";
}
# eof - basename02.pl

index -|- top

checked by tidy  Valid HTML 4.01 Transitional