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

I've been working on this for 2 days now, and for the life of me I can't figure it out...Though I have a feeling it's probably some blatently obvious thing I'm overlooking. When I run my script, I get the following error:
Missing right curly or square bracket at line 926, at end of line.
Now, when I remove one certain subroutine, it gives me another error (below), but doesnt die.
Can't locate Term/ReadLine/Perl.pm in @INC
The subroutine that I remove is below, I sure hope someone can help me out...and just in case, I'll include the modules I'm using:
BEGIN {use CGI::Carp qw(fatalsToBrowser)} use Cwd; $cwd = getcwd(); $cwd =~ s/\\/\//g; sub setData { my($zero) = chr(0); my($one) = chr(1); my($two) = chr(2); open(NDAT,">$path/trivia_dat.cgi"); foreach $i (0..($n_q - 1)) { print NDAT "#"; print NDAT $INPUT{"q$i"}; print NDAT "$zero"; foreach $j (0..($n_a - 1)) { if($INPUT{"q$i-c"} eq $j) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$two"."$one"; } elsif($j < ($n_a - 1)) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$one"; } else { print NDAT $INPUT{"q$i-a$j"}; print NDAT "\n"; } } close(NDAT); }

Replies are listed 'Best First'.
Re: Brackets are driving me insane....
by mwp (Hermit) on Dec 30, 2000 at 00:58 UTC
    Ya forgot one! =)
    print NDAT "$one"; } else { print NDAT $INPUT{"q$i-a$j"}; print NDAT "\n"; } # oops! }

    Close the if, close the inner foreach, close the outer foreach, close the subroutine. As to the other problem, we'll need more info--like environment, the first few lines of your program, how it's being called, etc.

Re: Brackets are driving me insane....
by epoptai (Curate) on Dec 30, 2000 at 05:15 UTC
    Comments on closing brackets can be quite useful for keeping track of flow and bracket symmetry. I went through your sub commenting the closures and the problem quickly revealed itself:
    sub setData { my($zero) = chr(0); my($one) = chr(1); my($two) = chr(2); open(NDAT,">$path/trivia_dat.cgi"); foreach $i (0..($n_q - 1)) { print NDAT "#"; print NDAT $INPUT{"q$i"}; print NDAT "$zero"; foreach $j (0..($n_a - 1)) { if($INPUT{"q$i-c"} eq $j) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$two"."$one"; }# if elsif($j < ($n_a - 1)) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$one"; }# elsif else { print NDAT $INPUT{"q$i-a$j"}; print NDAT "\n"; }# else }# foreach close(NDAT); }# foreach
    Oops!
Re: Brackets are driving me insane....
by turnstep (Parson) on Dec 30, 2000 at 01:11 UTC

    A good editor ( emacs, hint hint) will match closing tags for you, so you can add one in at the bottom and see what it matches, or take them away and add them in from the bottom up to see if everything is where it is supposed to be.

      Heh. Wicked t-shirt.

      vi can also find matching brackets with a simple '%' when your cursor is over a {opening,closing}-bracket; or you can ':set sm' in your .exrc.

Re: Brackets are driving me insane....
by Trimbach (Curate) on Dec 30, 2000 at 00:59 UTC
    Looks like you're missing a right bracket here:
    } else { print NDAT $INPUT{"q$i-a$j"}; print NDAT "\n";

    Gary Blackburn
    Trained Killer

Re: Brackets are driving me insane....
by I0 (Priest) on Dec 30, 2000 at 01:11 UTC
    sub setData { my($zero) = chr(0); my($one) = chr(1); my($two) = chr(2); open(NDAT,">$path/trivia_dat.cgi"); foreach $i (0..($n_q - 1)) { print NDAT "#"; print NDAT $INPUT{"q$i"}; print NDAT "$zero"; foreach $j (0..($n_a - 1)) { if($INPUT{"q$i-c"} eq $j) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$two"."$one"; } elsif($j < ($n_a - 1)) { print NDAT $INPUT{"q$i-a$j"}; print NDAT "$one"; } else { print NDAT $INPUT{"q$i-a$j"}; print NDAT "\n"; } } } close(NDAT); }