如何在Perl中构造与操作系统无关的文件路径,包括可选的Windows驱动器号? [英] How can I construct OS-independent file paths in Perl including an optional Windows drive letter?

查看:82
本文介绍了如何在Perl中构造与操作系统无关的文件路径,包括可选的Windows驱动器号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Perl脚本中构造一个文件路径.我应该使用哪个路径分隔符来允许我的脚本在Windows和Unix上运行?

I need to construct a file path inside a Perl script. Which path separator should I use to allow my script to work on both Windows and Unix?

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

Keep in mind that Windows needs a drive letter.

推荐答案

您要 File :: Spec catpath:


       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 );

这篇关于如何在Perl中构造与操作系统无关的文件路径,包括可选的Windows驱动器号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆