hi我写了一个代码
#!/tools/baton/perl/5.12.1/bin/perl
use strict;
use YAML;
use YAML 'LoadFile';
use Data::Dumper;
my $file_yml;
my $path = "//IP2/D21EV/2hw/semi_axi_10g_ethernet/info.yml";
my %hash = open(READ, p4 print -q $path|") or die "could not open ";
print Dumper (%hash);
它给了我:
$VAR1 = {
'39807' => undef
};
您的代码中有一些语法错误(缺少双引号),但这可能只是复制粘贴问题。
主要问题似乎是使用了open返回的值来填充哈希,但open
不返回文件的内容。事实上,如文档所述,如果您使用它来打开管道,它会返回子进程的PID。
实际上,您需要从文件句柄中读取以获取其内容。
例如
my %hash;
open my $PIPE, '-|', qw( ls -s );
while (<$PIPE>) {
my ($size, $file) = split;
$hash{$file} = $size;
}