Perl 从变量获取输出

Perl 从变量获取输出,perl,perl-module,Perl,Perl Module,release.ms1的内容 use strict; use warnings; $manifest=read_file("release.ms1"); print "$manifest\n"; my @new=split('\.',$manifest); my %data=@new; print "$data('vcs version')"; 错误: vcs.版本:12321 vcs.路径:CiscoMain/IT/GIS/trunk VCS版本:12321 vcspa

release.ms1的内容

 use strict;
 use warnings;

 $manifest=read_file("release.ms1");
 print "$manifest\n";

 my @new=split('\.',$manifest);

 my %data=@new;

 print "$data('vcs version')";
错误:

vcs.版本:12321

vcs.路径:CiscoMain/IT/GIS/trunk

VCS版本:12321

vcspath:CiscoMain/IT/GIS/trunk

在./script.pl第33行的哈希赋值中,元素的奇数

在./script.pl第35行的打印中使用未初始化的值

我需要像这样的输出:

vcs.version:12312321
vcs.path:CiscoMain/IT/GIS/trunk

您的
split
函数正在分配:

version=12312321
path=CiscoMain/IT/GIS/trunk
当您将列表分配给散列时,它必须具有偶数个元素,因为它们必须是交替的键和值

看起来您实际上想要做的是在换行符和冒号上拆分
$manifest
,并用空格替换键中的点

$new[0] = 'vcs'
$new[1] = 'version:12312321\nvcs'
$new[2] = 'path:CiscoMain/IT/GIS/trunk'

哈希键被大括号包围,而不是圆括号。

您给出了一个引用第27行的错误,但只提供了11行代码<代码>读取文件未定义。在
$manifest
前面需要
my
。在我看来,第27行是
my%data=@new
和29是
打印
行。嗨,Barmar,实际上我已经跳过了这里不需要的行,那么你应该让读者更容易理解并指出错误消息所指的行。嗨,Barmar,split工作正常。但哈希函数并不令人担忧,最近PHP太多了,我把赋值写错了。
my @new = split(/[.\n]/, @manifest;
my %data;
for (my $i = 0; $i < @new; $i += 2) {
    my $key = $new[$i];
    $key =~ s/\./ /g;
    $data{$key} = $new[$i+1];
}
print $data{'vcs version'};