简体   繁体   English

Perl:从命令行读取路径

[英]Perl: Read path from command line

I'm newbie in perl and I got some problem with one thing. 我是Perl的新手,一件事有点问题。

I have code: 我有代码:

$original_file = "y:\\Users\\XXX\\perlScript\\test1.xml";
$new_file = "y:\\Users\\XXX\\perlScript\\summary_test1.xml";
copy($original_file, $new_file) or die "File cannot be copied";

I need read path from cmd command line (I use batch file). 我需要从cmd命令行读取路径(我使用批处理文件)。 For Example: 例如:

>summary.bat c>\path\file_name.xml

After copy I'd like create summary_file_name.xml to same folder 复制后,我想将summary_file_name.xml创建到同一文件夹

Thanks 谢谢

Are you asking how a Perl program gets its command line arguments? 您是在问Perl程序如何获取其命令行参数吗? You'll find them in the @ARGV array. 您将在@ARGV数组中找到它们。

You want to use File::Basename . 您想使用File::Basename This is a standard library in Perl, at least as early as 5.14, so you do not need to install anything new. 这是Perl中的标准库,至少早在5.14之前,因此您不需要安装任何新东西。

use File::Basename;
my($filename, $directories, $suffix) = fileparse($original_file);
my $new_file = $directories . "/summary.xml";

For more information, see the Perl Docs . 有关更多信息,请参见Perl Docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM