use File::Basename;
($name,$path,$suffix) = fileparse($fullname,@suffixlist);
$name = fileparse($fullname,@suffixlist);
$basename = basename($fullname,@suffixlist);
$dirname = dirname($fullname);
fileparse 函数可以返回文件名,目录路径,如果后面用$suffix 的话还会返回文件的后缀名。$suffix 可以是正则表达式qr/\.[^.]*/ 其中qr 创建正则。
"fileparse"
my($filename, $directories, $suffix) = fileparse($path);
my($filename, $directories, $suffix) = fileparse($path, @suffixes);
# On Unix returns ("baz", "/foo/bar/", "")
fileparse("/foo/bar/baz");
# On Windows returns ("baz", "C:\foo\bar\", "")
fileparse("C:\foo\bar\baz");
# On Unix returns ("", "/foo/bar/baz/", "")
fileparse("/foo/bar/baz/");
If @suffixes are given each element is a pattern (either a string
or a "qr//") matched against the end of the $filename. The
matching portion is removed and becomes the $suffix.
# On Unix returns ("baz", "/foo/bar/", ".txt")
fileparse("/foo/bar/baz.txt", qr/\.[^.]*/);
basename 函数。用来返回文件名,或者是去除了文件后缀名的文件名(如果加了$suffix)
#perl -MFile::Basename -e '$_ = basename("/usr/bist.file",".file");print'
test
dirname 函数
[root@PC_IN_LAN learnperl]#perl -MFile::Basename -e '$_ = dirname("/usr/bin/test.txt");print qq/$_\n/;'
/usr/bin
阅读(4566) | 评论(0) | 转发(0) |