$file = $query->upload('uploaded_file'); if (!$file && $query->cgi_error) { print $query->header(-status=>$query->cgi_error); exit 0; } #### Can't use an undefined value as a HASH reference at /path/to/search-howto.cgi line 185. #### sub upload_image { ## pull the file in a variable my $fh = $query->upload('upload'); ## determine the file type via the headers my $type = $query->uploadInfo($fh)->{'Content-Type'}; ## take action based on type if ($type eq 'text/html') { ## hash of file names to write to my %destination = ( 'match' => "match.html", 'no_match' => "no_match.html"); ## open the file to be written open(HTML, ">/www/$destination{$formdata{filename}}") or die "Cant open HTML file for writing : $!\n"; ## if file is determined to be text/html write contents to appropriate location while(<$fh>) { print HTML "$_\n"; } close(HTML); ## otherwise set error for later notification within html } else { $error = "on"; } }