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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.