如何在Perl中构建与OS无关的文件路径,包括可选的Windows驱动器号?

前端之家收集整理的这篇文章主要介绍了如何在Perl中构建与OS无关的文件路径,包括可选的Windows驱动器号?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在Perl脚本中构造一个文件路径.我应该使用哪个路径分隔符来允许我的脚本在Windows和Unix上运行?

请记住,Windows需要驱动器号.

解决方法

你想要 File::Spec的猫道:
       catpath()
         Takes volume,directory and file portions and returns an entire path.
         Under Unix,$volume is ignored,and directory and file are
         concatenated.  A '/' is inserted if need be.  On other OSes,$volume
         is significant.

             $full_path = File::Spec->catpath( $volume,$directory,$file );
原文链接:https://www.f2er.com/Perl/172929.html

猜你在找的Perl相关文章