在我的perl脚本中,我有param $FILE = / etc / sysconfig / network
以这种方式(在perl中)我可以只剪切目录并将目录放在$DIR param中
为了得到:
$DIR=/etc/sysconfig (like dirname /etc/sysconfig/network in shell script)
解决方法
use File::Basename; ($name,$path,$suffix) = fileparse($fullname,@suffixlist); $name = fileparse($fullname,@suffixlist); $basename = basename($fullname,@suffixlist); $dirname = dirname($fullname);
阅读更多关于File::Basename在perldoc.