Perl 变量 Perl 变量



my code :

if ($funcarg =~ /^test (.*)/) {
my $target1 = "http://$1/script/so.php";
system("wget $target1");

因此,当我键入 perl a.pl 127.0.0.1 时,脚本必须下载 http://127.0.0.1/script/so.php,但不幸的是它没有。 我的错误在哪里?

[root@localhost perl]# perl a.pl 127.0.0.1
http:///script/so.php: Invalid host name.

不清楚你的命令行参数是如何从@ARGV$funcarg的。或者它是如何从127.0.0.1到(大概(test 127.0.0.1.我认为这就是你出错的地方。我认为$funcarg不包含您在运行正则表达式匹配之前认为它的作用。

这段代码可以做我认为你想要的。但是我不得不编造两行(如注释所示(,我很确定您对这两行的版本是您的误解所在。

#!/usr/bin/perl
use strict;
use warnings;
@ARGV or die "No argument givenn";
# I've made up the next two lines. But I think
# this is where your bug is.
my $host = $ARGV[0];
my $funcarg = "test $host";
if ($funcarg =~ /^test (.*)/) {
my $target1 = "http://$1/script/so.php";
print "$target1n";
system("wget $target1");
}

最新更新