perl - perl 变量 perl 变量
问题描述
我的代码:
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
to获取$funcarg
。或者它是如何从127.0.0.1
到(大概)test 127.0.0.1
。我认为这就是你出错的地方。我认为这$funcarg
不包含您在运行正则表达式匹配之前的想法。
这段代码做我认为你想要的。但我不得不编造两行(用注释标记),我很确定你对这两行的版本是你误解的地方。
#!/usr/bin/perl
use strict;
use warnings;
@ARGV or die "No argument given\n";
# 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 "$target1\n";
system("wget $target1");
}
推荐阅读
- c++ - 使用 g++ 预处理器进行替换会导致链接错误
- php - 如何为centos安装特定的包和版本
- sql - 检查 NULL 时 SQL 查询中的可选参数非常慢
- git - Git项目子模块组织
- angular - 不允许的 MIME 类型(“text/html”)错误 - Angular Github 页面
- symfony - Symfony 4.3 错误:您不能同时设置“template.hinclude_default_template”和“fragments.hinclude_default_template”
- java - 用JAVA填充二维数组
- mongodb - MongoDB - 加入集合、过滤和排序
- html - 如何在网页中流式传输 mp3 文件?
- azure - .NET 堆栈中的 Azure App Service 可以执行 PHP 代码