0
votes

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?

2

2 Answers

2
votes

You have to store references in the inner structures:

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

Try:

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

Then:

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