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

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)

Replies are listed 'Best First'.
This has nothing to do with a hash ref.
by Anonymous Monk on Dec 21, 2002 at 19:12 UTC
    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 {