in reply to Re^2: IE vs. Firefox : Can't use an undefined value as a HASH reference error
in thread IE vs. Firefox : Can't use an undefined value as a HASH reference error

uploadInfo is from CGI.pm, so you want the source from the CGI module?
That would be the relevant code, yes. Not being a frequent CGI programmer, myself, I didn't recognize that it was a CGI function. So here's the source:
sub uploadInfo { my($self,$filename) = self_or_default(@_); return $self->{'.tmpfiles'}->{$filename}->{info}; }
It's a method, and you're calling it as an ordinary sub.

Update: as dragonchild points out, that's not the problem. So the critical issue looks like: what is the value of $filename? It may require some exploration and dumping of data to see what value it should have in order to work.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^4: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by dragonchild (Archbishop) on Feb 24, 2005 at 19:11 UTC
    Nope. Every function in CGI can be called as either a function or a method. That's what the self_or_default() function does.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^4: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by hmbscully (Scribe) on Feb 24, 2005 at 19:16 UTC
    Thanks. I'll look into the object method. I still don't understand why the script works when called from a form in Firefox but not in IE. Because it seems that uploadInfo works in one case but not another.
      My object method suggestion was wrong. However, you can dump the data structure to see why it (apparently) isn't finding the information:
      my $def_obj = CGI::self_or_default($filename); use Data::Dumper; print Dumper $def_obj->{'.tmpfiles'};

      Caution: Contents may have been coded under pressure.
        I could if I had that Data:: module or the power to have it installed. Alas, I do not. I do thank you for your continued suggestions. I checked the value of $filename and it is the name of the file I'm attempting to upload. I had an older version of my script that worked, but it didn't pass variables and I had to create a new subroutine for each file upload field (I have two):
        ## OLD CODE sub Store_Results{ my $data; my $mime = uploadInfo($File_Name)->{'Content-Type'}; open (STORAGE, ">$Directory/$File_Name") or die "Error: $Directory +/$File: $!\n"; if($mime !~ /text/){ binmode ($File_Name); binmode (STORAGE); } while( read($File_Name, $data, 1024) ){ print STORAGE $data; } close STORAGE; } ## NEW CODE #stores uploaded files sub storeFiles{ my($filename, $directory) = @_; #name subroutine variables my $data; my $mime = uploadInfo($filename)->{'Content-Type'}; open (STORAGE, ">$directory/$filename") or die "Error: $directory/ +$filename: $!\n"; if($mime !~ /text/){ binmode ($filename); binmode (STORAGE); } while( read($filename, $data, 1024) ){ print STORAGE $data;} close STORAGE; }
        I was trying to make the code more reusable and so re-wrote the subroutine to pass the file name and the directory path, but it obviously doesn't work.
        my $mime = uploadInfo($File_Name)->{'Content-Type'};
        works, but
            my $mime = uploadInfo($filename)->{'Content-Type'};
        does not.