【问题标题】:Array of hash; Can't use string ("1") as an ARRAY ref while "strict refs"?哈希数组;不能在“严格引用”时使用字符串(“1”)作为数组引用?
【发布时间】:2014-10-16 10:10:54
【问题描述】:

我想在 perl 中创建一个二维数组,我发现最简单的方法是使用哈希数组。 有我的哈希数组

my %tstat;

while ( $index <= $i ) {
    $curfile[$index] = $camera_path[$index] . "/current.jpg";
    $tstat{$index} = stat( $curfile[$index] );
    $index++;
}

$index = 0;
while ( $index <= $i ) {
    if ( $tstat{$index}[9] != $last_direct_img[$index] || $buffer_init-- > 0 ) {
        ...;
        $index++;
    }
}

它告诉我

在“strict refs”时不能使用字符串(“1”)作为数组引用

我尝试用 {9} 更改 [9],但还是一样,为什么?

【问题讨论】:

    标签: arrays perl hash


    【解决方案1】:

    您必须在内部结构中存储引用:

    $tstat{$index} = [ stat($curfile[$index]) ];
    

    【讨论】:

      【解决方案2】:

      试试:

      my @status_info = stat($curfile[$index]);
      $tstat{$index} = \@status_info;
      

      然后:

      my $mtime = $tstat{$index}->[9];
      ...
      

      【讨论】:

        猜你喜欢
        • 2020-05-22
        • 2019-06-11
        • 2020-02-21
        • 2016-12-11
        • 2014-07-18
        • 1970-01-01
        • 2021-09-23
        • 2011-12-19
        相关资源
        最近更新 更多