Perl 新手和我的局限性令人沮丧。任何帮助是极大的赞赏。
创建脚本,它将:
- 输入文件并解析测试模式匹配
 - 将特定匹配的单词输出到变量
 - 针对变量运行外部 Windows 程序 (nslookup),
 - 解析 nslookup 的输出以进行测试模式匹配
 - 将特定匹配的单词输出到变量
 - 在两个变量之间执行替换
 - 然后将修改后的文本输出到文件中
 
在 input.txt 文件中回显“这是一台机器:ford.com 测试”
我的打印输出有问题,因为我不断收到以下信息
在 test21.pl 第 38 行的 void 上下文中无用使用字符串。
非权威答案:在 test21.pl 第 39 行的打印中使用未初始化的值 $_。
0
#!/bin/perl
use strict;
use warnings;
use Net::Nslookup;
use File::Copy;
sub host {
    my $result;
    my $node = shift;
    print system("nslookup $node.com | findstr ^Name: >> POOH");
    open( my $stuff, "<", "POOH" ) || die "Can't open input.txt: $!";
    while (<$stuff>) {
        if (/(Name:)(\s+)(\w+)/) {
            $result = $3;
        }
    }
    return $result;
}
my $captured;
my $captured2;
my $jeff;
my $in   = 'input.txt';
my $out  = 'output.txt';
my $test = 'test.txt';
copy( $in, $out ) || die "File cannot be copied.";
open OUTPUT, "< $out"  || die "Can't open input.txt: $!";
open TEST,   "> $test" || die "Can't open input.txt: $!";
while (<OUTPUT>) {    # assigns each line in turn to $_
    if (/(Machine:)(\s)(\w+)/) {
        $captured = $3;
        $jeff     = host($captured);
    }
    "s/$captured/$jeff/g";
    print TEST;
}