Hello all!!! I've been having a little bit of trouble with the exists and defined functions. When I try to use the expression: print DATA "\+$exp[1]" if exists $exp[1]; and so on, but I get this message "exists operator argument is not a HASH element" I have no idea what's going on. Help!


Here's all code:
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); #use strict; use CGI; my $q = new CGI; my @exp = $q->param("explorer"); my $hoursworked = $q->param("hrswrked"); my $name = $q->param("name"); my $num = @exp; (my $sec,my $min,my $hour,my $mday,my $mon,my $year,my $wday,my $yday, +my $isdst)=localtime(time); my $month = $mon+1; my $year1 = $year+1900; my $date = "$month\/$mday\/$year1"; my @months = qw(January February March April May June July August Sept +ember October November December); if ($q->param("submit")) { if (($hoursworked eq "") || ($num == 0)) { print <<"PrintTag"; <html><head><title>Insufficient information</title> </head><body bgcolor = "white" text="black" link="black"> <BASE HREF="http://nbpdexplorers.port5.com/"> <br><br><center><h2>Insufficient information</h2></center> <blockquote><blockquote><center><p><b>The following field(s) were empt +y:<br><br> <table> PrintTag if ($hoursworked eq "") { print "<tr><td><li><b>Hours Worked</b></li></td></tr>"; } if ($num == 0) { print "<tr><td><li><b>Explorers</b></li></td></tr>"; } print <<"PrintTag"; </table></p></center></blockquote></blockquote> <center><h3>Please click the \'Back\' button on your browser to try ag +ain</h3></center></html> PrintTag exit; } @exp = sort(@exp); @date = split(/\//, $date); $month = shift(@date); $month--; $month = @months[$month]; open(DATA, ">>/host/n/b/p/p/o/r/nbpdexplorers.port5.com/cgi-bin/data2. +txt") or die "Cannot open database file: $!"; flock(DATA, 2); print DATA "$month\+$exp[0]"; print DATA "\+$exp[1]" if exists $exp[1]; #print DATA "\+$exp[2]" if exists $exp[2]; #print DATA "\+$exp[3]" if exists $exp[3]; #print DATA "\+$exp[4]" if exists $exp[4]; #print DATA "\+$exp[5]" if exists $exp[5]; #print DATA "\+$exp[6]" if exists $exp[6]; #print DATA "\+$exp[7]" if exists $exp[7]; #print DATA "\+$exp[8]" if exists $exp[8]; #print DATA "\+$exp[9]" if exists $exp[9]; #print DATA "\+$exp[10]" if exists $exp[10]; #print DATA "\+$exp[11]" if exists $exp[11]; print DATA "\+$hoursworked\n"; } flock(DATA, 8); close(DATA); } print <<"PrintTag"; <html><head><title>Record Accepted</title> </head><body bgcolor = "white" text="black" link="black"> <BASE HREF="http://nbpdexplorers.port5.com/"> <br><br><center><h2>Request Add Record Accepted</h2></center><br><br> <blockquote><blockquote><center><p><font size="+1">To check hours work +ed status or to edit explorer listing, click <a href="http://nbpdexpl +orers.port5.com/cgi-bin/mainpage.cgi?name=$name">here</a></font></p>< +/center></blockquote></blockquote> <br><br><br><br><br><br><br><br><br><br><blockquote><blockquote><cente +r><p><font size="+1"><a href="http://nbpdexplorers.port5.com">Click H +ere To Log Off</a></font></p></center></blockquote></blockquote> PrintTag

In reply to exists and defined functions by arrow

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.