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

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.

Replies are listed 'Best First'.
Re^7: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by Roy Johnson (Monsignor) on Feb 24, 2005 at 20:15 UTC
    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.
Re^7: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by dragonchild (Archbishop) on Feb 24, 2005 at 20:09 UTC
    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.

      $File_Name = Get_File_Name(param('filename')); sub Get_File_Name{ if($ENV{HTTP_USER_AGENT} =~ /win/i){ fileparse_set_fstype("MSDOS"); } elsif($ENV{HTTP_USER_AGENT} =~ /mac/i) { fileparse_set_fstype("MacOS"); } my $full_name = shift; $full_name = basename($full_name); $full_name =~ s!\s!\_!g; # Replace whitespace with _ return($full_name); } storeFiles($File_Name, $Directory); 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; }
      So I'm getting $File_Name using calling $Get_File_Name with param() and getting $filename in the subroutine with my($filename, $directory) = @_; #name subroutine variables. I will readily admit I don't understand the @_ very much. I printed both variables to see what they were and they both had the same value (a filename: test_file.doc), which is what I'd expect.