in reply to Re^3: 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

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.
  • Comment on Re^4: IE vs. Firefox : Can't use an undefined value as a HASH reference error

Replies are listed 'Best First'.
Re^5: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by Roy Johnson (Monsignor) on Feb 24, 2005 at 19:36 UTC
    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.
        print "<$_>\n" for keys %{$def_obj->{'.tmpfiles'}};
        instead of using Dumper.
        Update: added brackets around $_, in case of sneaky whitespace.

        Caution: Contents may have been coded under pressure.
        I would compare how you get $File_Name and how you get $filename. If you're just passing it into the subroutine, that means you changed somethign else. Also, how are you calling storeFiles()?

        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.