Chinaunix首页 | 论坛 | 博客
  • 博客访问: 836239
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-13 21:45:47

  1. use File::Basename
  2. my $file = "/usr/bin/perl";
  3. my $basename = basename $file;
  4. my $dirname = dirname $file;

  5. print "$basename, $dirname";

  6. #perl, /usr/bin
fileparse
  1. $filepath = /home/test/my.pl
  2. my ($filename, $filedir, $subffix) = fileparse($filepath, qr/\.[^.]*/);
  3. my $name = fileparse($filepath);
  4. print $filename, $filedir, $subffix, "\n"; #will be my, /home/test/ .pl
  5. print $name; #my.pl
You are guaranteed that "$directories . $filename . $suffix" will denote the same location as the original $path.
the $subffix is the optional if you put a string or pattern, may get $subffix.

fileparse_set_fstype
  1. my $type = fileparse_set_fstype();
  2. my $previous_type = fileparse_set_fstype($type);
Valid $types are "MacOS", "VMS", "AmigaOS", "OS2", "RISCOS",
           "MSWin32", "DOS" (also "MSDOS" for backwards bug compatibility),
           "Epoc" and "Unix" (all case-insensitive).  If an unrecognized $type
           is given "Unix" will be assumed.





阅读(649) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~