I'm trying to become more comfortable with hashes, as well as create some toolkit code for my CGI scripts. Unfortunately, I'm running into some errors that I either don't understand or don't understand the explanations that I've found.
Consider, if you will:
#!/usr/bin/perl -wT use strict; $|++; use constant ERROR_BADCONFIG => { Type => "Configuration", Description => "This script requires the module listed " . "in the following details; please make " . "sure the module is properly installed.", Fatal => 1 }; eval( "use CGI ':standard'" ); printError( $@,ERROR_BADCONFIG ) if $@; eval( "use MIME::Lite;" ); printError( $@, ERROR_BADCONFIG ) if $@; use CGI; my $cgi = CGI->new(); print $cgi->header; print $cgi->start_html( "Results" ); print "Configuration OK"; print $cgi->end_html; exit 1; sub printError { my $errortext = shift; my ( %errorhash ) = @_; print "$errorhash{ 'Type' } Error Detected\n", "$errorhash{ 'Description' }\n", "Error Details: $errortext\n"; if ( $errorhash{ "Fatal" } ) { die "Fatal Error Detected" }; }
As I'm sure the most experienced among you recognize that this contains a number of flaws, including the ones that Perl reports:
Reference found where even-sized list expected at errors.cgi line 42.
Use of uninitialized value in concatenation (.) at errors.cgi line 44.
Use of uninitialized value in concatenation (.) at errors.cgi line 44.
I've tried a dozen variations on the theme and have spent several hours scouring Search, Super Search, the FAQ's, the POD, and several other sources, but I'm not getting it.
Where am I going wrong? I'm trying to pass a hash and a scalar to my printError() routine (Perl 5.6.0).
Would someone mind sending this apprentice a message from the Clue server?
--f
In reply to Errors Using Hashes and Subroutines by footpad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |