在perl中需要p4 print命令帮助

时间:2015-11-27 14:47:54

标签: perl perforce

你好我写了一段代码

#!/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

        };

1 个答案:

答案 0 :(得分:5)

您的代码中存在一些语法错误(缺少双引号),但它可能只是复制“粘贴问题”。

主要问题似乎是您使用open返回的值来填充哈希值,但open不会返回文件的内容。实际上,如文档所述,如果您使用它来打开管道,它将返回子进程的PID。

您需要从文件句柄中实际读取才能获取其内容。

E.g。

my %hash;
open my $PIPE, '-|', qw( ls -s );
while (<$PIPE>) {
    my ($size, $file) = split;
    $hash{$file} = $size;
}