chriso has asked for the wisdom of the Perl Monks concerning the following question:

When I check the below script with "perl -w -c" I get the following error messages (shortened for space consideration):

Global symbol "@allquestions" requires explicit package name at makequiz.cgi line 22 and line 46.
Global symbol "$anslength" requires explicit package name at makequiz.cgi line 27 and line 34.
Global symbol "@allanswers" requires explicit package name at makequiz.cgi line 28 and line 45.

I have tried placing "my" and "local" in front of these but I still get the same message. What does it mean and how do I fix it? Thanks.

#!/usr/bin/perl #c:\sambar50\perl\perl.exe use CGI qw(:standard); use strict; use warnings; print header; local $/ = "~\n"; # *** CHANGES INPUT RECORD SEPARATOR TO ~line brea +k print start_html (-title=>'quiz', -BGCOLOR=>'beige'); print start_form (-method=>'POST', -action=>"http://localhost/cgi-bin/ +gradequiz.cgi"); my $file = param('file'); open (FILE, $file) || die "Cannot open $file: $!"; while (<FILE>) { # ** READS EACH LINE OF TEXT FROM FILE chomp; # ** BY DEFAULT, CHOMPS OFF $/ FROM EACH LINE my ($type, $value) = split (/:/, $_); # ***** SPLITS EACH LINE BY +TYPE AND CONTENT if ($type =~ m/q/i) { # ** CHECKS FOR QUESTION LINE & PRINTS QUESTI +ON print "<B>$value</B><BR>"; @allquestions = (@allquestions, $value); } if ($type =~ m/a/i) { # ** CHECKS FOR ANSWER LINE my @answers = split (/,/, $value); # ** SPLITS ANSWER LINE IN +TO ARRAY $anslength = @answers; # ** LENGTH OF @ANSWERS @allanswers = (@allanswers, $value); } #** CHECKS FOR SELECTION LINE AND if ($type =~ m/^s/) { # ** TYPE OF ANSWER BOX my %selections = split (/,/, $value); my @options = keys (%selections); if ($anslength > 1) { # ** DETERMINES TO USE RADIO OR CHECKB +OX print checkbox_group(-name=>$type, -values=>\@options, -linebre +ak=>'true', -labels=>\%selections); }else { print "<BR>"; print radio_group(-name=>$type, -values=>\@options, -linebre +ak=>'true', -labels=>\%selections, -default=>'-'); } print "<BR><HR><BR>"; } # END IF STATEMENT } # ** END WHILE STATEMENT close (FILE); print hidden(-name=>"answers", -default=>\@allanswers); print hidden(-name=>"questions", -default=>\@allquestions); print "<CENTER>"; print submit (-value=>'Grade') . "&nbsp; &nbsp;"; print reset (-value=>'Reset answers'); print "</CENTER>"; print end_form; print end_html;

Replies are listed 'Best First'.
Re: What is an
by dragonchild (Archbishop) on Dec 17, 2001 at 20:14 UTC
    Change each of the blocks similar to the following in this manner:
    my @allquestions; if ($type =~ m/q/i) { # ** CHECKS FOR QUESTION LINE & PRINTS QUESTI +ON print "<B>$value</B><BR>"; @allquestions = (@allquestions, $value); }
    In addition, make the following change:
    @allquestions = (@allquestions, $value); # Should be ... push @allquestions, $value;

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Hi Dragonchild, That was for arrays, how do we do it for simple variables. my $DAEMON_LOG="$IPMAN_HOME/data/daemon_log.txt"; my $DAEMON_ERROR_LOG ="$IPMAN_HOME/data/daemon_error_log.txt"; I have used my before any thing expect the packag declaration & I am getting the error Global symbol "$DAEMON_LOG" requires explicit package name at ipmand line 348. Global symbol "$DAEMON_LOG" requires explicit package name at ipmand line 349. Global symbol "$DAEMON_LOG" requires explicit package name at ipmand line 350. Global symbol "$DAEMON_ERROR_LOG" requires explicit package name at ipmand line 354. Global symbol "$DAEMON_ERROR_LOG" requires explicit package name at ipmand line 355. Global symbol "$DAEMON_ERROR_LOG" requires explicit package name at ipmand line 356.
Re: What is an
by fuzzysteve (Beadle) on Dec 17, 2001 at 20:10 UTC
    where did you put the my's in? if you did it at the first instance of the variables, the the use outside the while loop will still cause problems (as its local to the loop). if you stick the declarations before the begining of the while loop it stands a better chance of working.
    Define stuff at the top, unless its temporary and used only within a loop. easier to find it with a program of this size.