Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

ERROR "Software error: Can't use an undefined value as a HASH reference at upload.pl line 134."

How can this POSSIBLY be the case when my test proves 100% it's not undefined? This is the line on line 134 and it's saying $file is undefined, right? Well WRONG, the print statement exactly one line above prints the value correctly. Could something else be the problem?

print "file = \"$file\""; my $type = uploadInfo($file)->{'Content-Type'};

Replies are listed 'Best First'.
Re: Undefined hash value (or so it thinks)
by Corion (Patriarch) on Apr 01, 2004 at 20:42 UTC

    You're not looking at the whole picture. Your $file might well be defined, but uploadInfo($file) seems to be undefined, according to the error you get.

    Look at the sub uploadInfo and check what it returns. And modify your program accordingly:

    use Data::Dumper; print qq(file is >>$file<<\n); my $info = uploadInfo($file); if (defined $info) { print "Got info on $file: ", Dumper($info); } else { print "Uhoh. Couldn't get info on '$file'...\n"; }; my $type = $info->{'Content-Type'};
Re: Undefined hash value (or so it thinks)
by Thelonius (Priest) on Apr 01, 2004 at 20:39 UTC
    It's not saying that $file is undefined, it's saying that uploadInfo($file) is returning undefined.
Re: Undefined hash value (or so it thinks)
by Roy Johnson (Monsignor) on Apr 01, 2004 at 20:40 UTC
    Hash reference, not hash index. Apparently, uploadInfo($file) is returning undef, and you're trying to deref it.

    The PerlMonk tr/// Advocate