[英]How to take command line file input in Perl from user?
How to take command line file input in Perl from user ? 如何从用户的Perl中获取命令行文件?
my $filename = 'devices.xml';
my $filename1= 'discoveryinstances.xml';
Instead of using the static location of XMLfiles, Can i get a dynamic XML location from the user which may be in some other directory ? 而不是使用XML文件的静态位置,我可以从用户获得可能位于其他目录中的动态XML位置吗?
use XML::LibXML;
use XML::XPath;
use XML::XPath::XMLParser;
print "Enter the file location for devices.xml file"."\n";
my $firstfile =<STDIN>;
my $filename = chomp($firstfile);
print "Enter the file location for discoveryinstances.xml file"."\n";
my $secondfile =<STDIN>;
my $filename1=chomp($secondfile);
solution for this was : 解决方案是:
print "Enter the location:\n";
chomp( my $filename = <STDIN> );
You can also use this to take multiple input from the user 您也可以使用它来从用户那里获取多个输入
my @filename = <STDIN>;
In the array of filename u have all the files names that the user have given 在文件名数组中,您拥有用户提供的所有文件名
For fixed 2 files 对于固定的2个文件
my $firstfile =<STDIN>;
my $secondfile =<STDIN>;
Now u have both the files 现在你有两个文件
Use this module, Getopt::Long - Extended processing of command line options. 使用此模块, Getopt :: Long - 命令行选项的扩展处理。 This is best module for command line options.
这是命令行选项的最佳模块。
example like 例如
use strict;
use Getopt::Long;
use Data::Dumper;
my %args;
GetOptions( \%args, "filename1=s"
, "filename2=s"
) or die "Invalid Options \n";
print Dumper(\%args);
Run program like : 运行程序如:
abc.pl -filename1 "abc.xml" -filename2 "test.xml"
使用$ ARGV集合来读取命令行参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.