I try to add array in hash.
if ( not exists $hashtime{ $arr[0] }{ $date }{ $hour }{ $min } ) {
print "$min not exist";
$hashtime{ $arr[0] }{ $date }{ $hour }{ $min } = [ $sec ];
$create++;
};
And received the error:
Not a HASH reference at ./sort_log_by_ip.pl line 63, line 1.
Why is this code wrong?
In perldoc perldsc I see this construction, and I'm using something similar:
while ( <> ) {
next unless s/^(.*?):\s*//;
$HoA{$1} = [ split ];
}
Update
Code before:
if ( not exists $hashtime{ $arr[0] } ) {
$hashtime{ $arr[0] } = ( $date => { $hour => { $min => [ $sec ] } } );
$create++;
print "create for IP: $arr[0]\n";
}
if ( not exists $hashtime{ $arr[0] }{$date} ) {
$hashtime{ $arr[0] }{ $date } = ( $hour => { $min => [ $sec ] } );
$create++;
print "create for IP: $arr[0] DATE: $date\n";
}
if ( not exists $hashtime{ $arr[0] }{$date}{$hour} ) {
$hashtime{ $arr[0] }{ $date }{ $hour } = ( $min => [$sec] );
$create++;
print "create for IP: $arr[0] DATE: $date HOUR: $hour\n";
}