简体   繁体   中英

Array of hash; Can't use string (“1”) as an ARRAY ref while “strict refs”?

I want to do an array with 2 dimension in perl and I saw that the ease way to do it was with array of hash. there is my array of hash

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++;
    }
}

And it tells me

Can't use string ("1") as an ARRAY ref while "strict refs"

I have try to change [9] with {9} but it's the same, why?

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

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

Try:

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

Then:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM