in reply to Can't use an undefined value as a HASH reference

G'day Joe

It'd be nice to have a little more data. I think your __DIE__ handler is a great idea, but it's obviously not showing up the error. I can't tell you why. It looks like your code is getting a warning for no reason, but I can't tell you why that is so.

I have occasionally got HASH reference errors for nothing to do with hashes before and it's usually because I've forgotten to close some quotes or put in a semi-colon or whatever.

Nevertheless, I'm curious what your code returns for the following (just drop this in place of the segment you cut'n'pasted for us above):

use Data::Dumper; # Just grabbing the values of these so that # strict will cope with them. my $my_today_int = $today_int; my $my_no_call_requested_days = $no_call_requested_days; my $my_i = $i; my $my_user_id = $user_id; print STDERR Dumper($my_today_int, $my_i, $my_user_id); print STDERR Dumper($my_no_call_requested_days); { use strict; my @today = @{$my_no_call_requested_days->{$my_today_int}}; print STDERR "today:\n", Dumper(@today); my $ref = $today[$my_i]; print STDERR "ref:\n", Dumper($ref); my $employee_id = $ref->{'employee_id'}; print STDERR "employee_id: [$employee_id]\n"; if($employee_id eq $my_user_id) # should be "==" { print "They are the same!\n"; } }
It's functionally the same. This block is strict compliant and all the interesting values are printed to STDERR so that we can see things as they go on.

Hopefully rewriting to something like this will help identify the problem. Particularly if the bug is a missing close quote or } or similar above. :)

Hope it helps.

jarich

Replies are listed 'Best First'.
Re: Re: Can't use an undefined value as a HASH reference
by Anonymous Monk on Dec 20, 2002 at 22:18 UTC
    jarich, thank you for your reply.

    i pasted your code in my $SIG{'__DIE__'} adn here is it.
    local $SIG{'__DIE__'} = sub { my $my_today_int = $today_int; my $my_no_call_requested_days = $no_call_requested_days; my $my_i = $i; my $my_user_id = $user_id; my @dump = (); # Just grabbing the values of these so that # strict will cope with them. push @dump, $_[0], ""; push @dump, Dumper($my_today_int, $my_i, $my_user_id), ""; push @dump, Dumper($my_no_call_requested_days), ""; { use strict; my @today = @{$my_no_call_requested_days->{$my_today_int}}; push @dump, "today: " . Dumper(@today), ""; my $ref = $today[$my_i]; push @dump, "ref: " . Dumper($ref), ""; my $employee_id = $ref->{'employee_id'}; push @dump, "employee_id: [$employee_id]", ""; if($employee_id eq $my_user_id) # should be "==" { push @dump, "They are the same!", ""; } } &debug(@dump); };


    Here is the output.
    Can't use an undefined value as a HASH reference at /usr/local/www/cgi +-bin/kapc/md2/display_md_calendar.cgi line 1534. $VAR1 = 1041483600; $VAR2 = 0; $VAR3 = '0'; $VAR1 = { '1050120000' => [ { 'employee_id' => '34', 'type' => 'Routine' } ], '1049173200' => [ { 'employee_id' => '28', 'type' => 'Routine' } ], '1043211600' => [ { 'employee_id' => '0', 'type' => 'Hospital' }, { 'employee_id' => '34', 'type' => 'Routine' } ], '1043989200' => [ { 'employee_id' => '16', 'type' => 'Routine' }, { 'employee_id' => '10', 'type' => 'Routine' } ], '1043125200' => [ { 'employee_id' => '27', 'type' => 'Routine' } ], '1051329600' => [ { 'employee_id' => '24', 'type' => 'Routine' }, { 'employee_id' => '16', 'type' => 'Routine' } ], '1051243200' => [ { 'employee_id' => '24', 'type' => 'Routine' }, { 'employee_id' => '16', 'type' => 'Routine' } ], '1041483600' => [ { 'employee_id' => '27', 'type' => 'Routine' }, { 'employee_id' => '27', 'type' => 'Routine' } ], '1058932800' => [ { 'employee_id' => '23', 'type' => 'Routine' } ], '1053144000' => [ { 'employee_id' => '20', 'type' => 'Routine' } ], '1043298000' => [ { 'employee_id' => '0', 'type' => 'Routine' } ], '1046149200' => [ { 'employee_id' => '23', 'type' => 'Routine' }, { 'employee_id' => '28', 'type' => 'Routine' } ], '1046322000' => [ { 'employee_id' => '28', 'type' => 'Routine' } ], '1046408400' => [ { 'employee_id' => '10', 'type' => 'Extension' } ], '1048222800' => [ { 'employee_id' => '28', 'type' => 'Routine' }, { 'employee_id' => '10', 'type' => 'Routine' } ], '1045198800' => [ { 'employee_id' => '28', 'type' => 'Routine' }, { 'employee_id' => '13', 'type' => 'Routine' }, { 'employee_id' => '13', 'type' => 'Routine' } ], '1048136400' => [ { 'employee_id' => '28', 'type' => 'Routine' } ], '1042693200' => [ { 'employee_id' => '0', 'type' => 'Routine' } ], '1045285200' => [ { 'employee_id' => '0', 'type' => 'Routine' } ], '104400' => [ { 'employee_id' => '16', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Routine' }, { 'employee_id' => '28', 'type' => '-Routine' }, { 'employee_id' => '13', 'type' => '-Routine' }, { 'employee_id' => '13', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Extension' }, { 'employee_id' => '28', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Routine' }, { 'employee_id' => '24', 'type' => '-Routine' }, { 'employee_id' => '16', 'type' => '-Routine' } ], '18000' => [ { 'employee_id' => '16', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Routine' }, { 'employee_id' => '28', 'type' => '-Routine' }, { 'employee_id' => '13', 'type' => '-Routine' }, { 'employee_id' => '13', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Extension' }, { 'employee_id' => '28', 'type' => '-Routine' }, { 'employee_id' => '10', 'type' => '-Routine' }, { 'employee_id' => '24', 'type' => '-Routine' }, { 'employee_id' => '16', 'type' => '-Routine' }, { 'employee_id' => '0', 'type' => '-Routine' }, { 'employee_id' => '34', 'type' => '-Routine' }, { 'employee_id' => '24', 'type' => '-Routine' }, { 'employee_id' => '16', 'type' => '-Routine' }, { 'employee_id' => '20', 'type' => '-Routine' } ], '-154800' => [ { 'employee_id' => '0', 'type' => '-Routine' }, { 'employee_id' => '34', 'type' => '-Routine' }, { 'employee_id' => '24', 'type' => '-Routine' }, { 'employee_id' => '16', 'type' => '-Routine' }, { 'employee_id' => '20', 'type' => '-Routine' } ], '1045717200' => [ { 'employee_id' => '23', 'type' => 'Routine' } ] }; today: $VAR1 = { 'employee_id' => '27', 'type' => 'Routine' }; $VAR2 = + { 'employee_id' => '27', 'type' => 'Routine' }; ref: $VAR1 = { 'employee_id' => '27', 'type' => 'Routine' }; employee_id: [27]


    Here is the line 1534 where the script dies.
    if (%{@{$no_call_requested_days->{$today_int}}[$i]}->{'employee_id'} = += $user_id)
      Now I'm checking the employeeid from a hash and the userid and setting $ok to 1 if the two values are equal. Then I check ok and when I do the script dies on that line with "Can't use an undefined value as a HASH reference at /usr/local/www/cgi-bin/kapc/md2/display_md_calendar.cgi line 1570."

      Here is the code.

      my $value1 = int(%{@{$no_call_requested_days->{$today_int}}[$i]}->{'em +ployee_id'}); my $value2 = int($user_id); my $ok == (length($value1) == length($value2)) ? (1) : (0); if ($ok == 1) { for ($j=0; $j<length($value1); $j++) { if (substr($value1, $j, 1) != substr($value2, $j, 1)) { $ok = 0; } } } if ($ok == 1) # SCRIPT DIES HERE {