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

Below is my entire chat script to date and I know how many of you truly love giving your thoughts on other ways to do it and so forth but as for right now I think the script is moving along ok the way it is. This was posted in the CB earlier (part of it) and the problem was somewhere between using commas at the end of the lines and using semi colons.

Problem might be I've never been sure where to use commas instead of semi colons so I've only used commas for tables and forms and colons for everything else. I was wondering if someone could throw this in their debugger and give me pointers on what's wrong.

I get:

syntax error at chat.pl line 93, near "if" syntax error at chat.pl line 111, near "}" Execution of chat.pl aborted due to compilation errors.
Thanks for your time everyone.
#!/usr/bin/perl -w open( STDERR, ">>/home/sulfericacid/public_html/error.log" ) or die "Cannot open error log, weird...an error opening an error log +: $!"; use strict; use warnings; use POSIX; use CGI qw(:standard start_table end_table); use lib ""; #use Tie::IxHash; require SDBM_File; my %chat; my %chatorder; my $chat = "list.dbm"; #my $file = "iplog.txt"; tie %chat, "Tie::IxHash"; tie %chatorder, "Tie::IxHash"; tie %chat, 'SDBM_File', $chat, O_CREAT | O_RDWR, 0644; if ( !tied %chat ) { print "database unsuccessful $!.\n"; } print header, start_html; # # Time to keep accurate logs # my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); print "the local time is $hour:$min:$sec"; print start_table; print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"<font si +ze=2><b>ChatterBox version 1.0</b></font>" )); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); my $add; foreach (reverse keys (%chat)) { $add++; if ($add <= 10) { $chatorder{$_} = $chat{$_}; } } foreach (reverse keys (%chatorder)) { my ( $name, $message, $time ) = split /::/, $chatorder{$_}; print Tr(td({-width=>'700'},"<font color=blue>$name @ $time:</font +> $message")), } print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"<font si +ze=2 palign=right><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb +sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb +sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp +;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n +bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp +;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n +bsp;&nbsp;&nbsp;&nbsp;http://sulfericacid.perlmonk.org</b></font>" )) +; print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -size => 40 ) ) ), Tr( td("Message: "), td( textfield( -name => 'message', -size => 100 ) ) ), qq(<SCRIPT LANGUAGE="JavaScript">), Tr( td(), td(submit), td("document.write('<form><input type=button value=\"Refresh\" onC +lick=\"history.go()\"></form>)" ), ), end_form(), hr(), qq(</script>), qq(<a href="log.pl" target="new">chat logs</a>), if ( param() ) { my $name = param('name'); my $message = param('message'); my $cnt; open( LOG, "$file" ); $cnt = <LOG>; close(LOG); $cnt++; open( LOG, "> $file" ); print LOG $cnt; close(LOG); my $keeptime = join (':', $hour, $min, $sec); my $info = join ( '::', $name, $message, $keeptime ); $chat{$cnt} = $info; }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Syntax errors galore, need a good debugging
by chromatic (Archbishop) on Jun 25, 2003 at 05:53 UTC

    Exactly as the error message indicated, your error is in this line:

    qq(<a href="log.pl" target="new">chat logs</a>),

    Exactly as you suspected, you need a semicolon here to end the statement. Next time you see this error, trust the error message.

    Please don't ask people to count the lines of your program manually — use a good editor that either numbers your lines for you or can jump to a specified line. Look around there for the error. You could have solved this yourself in a few moments. Don't be afraid to try.

      I do trust the errors it gives me and I honestly did add a semi colon to the end which didn't solve the problem. I did try my hardest to solve this on my own but once I get the error shifted from one thing it moves on to the next and it feels like I'm getting further away from getting this done.

      Adding the semi colon gave me:

      syntax error at chat.pl line 90, near "qq(<a href="log.pl" target="new +">chat logs</a>);"


      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

        My guess is that you need a closing parenthesis for the table() function. Again, a good editor will help you with this. In vi or vim, you can put the cursor on one brace and hit the % to jump to the other.

        It's also good to get in the habit of typing the ending brace right after you type the opening brace. Then, back up a character and type the contents inside. Consistent indentation helps.

        One debugging trick I like is to comment out code. If I were you, I'd comment out everything before the table(), including the comma, and end the line with a semicolon right there. If that works, you know you've found the error. I use the __END__ token quite often to comment out everything after the current code.

Re: Syntax errors galore, need a good debugging
by dws (Chancellor) on Jun 25, 2003 at 17:37 UTC
    Problem might be I've never been sure where to use commas instead of semi colons so I've only used commas for tables and forms and colons for everything else.

    At your present skill level, two things might help:

    1. Be very, very careful with your indentation, particularly when you're passing a bunch of stuff to print. You've got at least one case of

    print a, b, c, ...
    This makes life hard on whoever is reading the code, and make it a bit more difficult to map an error message back to the source text. By being careful with indentation, it's a lot easier to see quickly when a comma is needed instead of a semicolon.
    print a, b, c, ...

    There's a problem in your code that'll pop right out if you do this. (And, strangely enough, it looks very close to the problem I pointed out to you via /msg yesterday.)

    2. If you're still having problems, use smaller statements. In this case,

    print a; print b; print c;

    It's a lot harder to embed an error in a long statement if you keep your statements short.

Re: Syntax errors galore, need a good debugging
by mpeppler (Vicar) on Jun 25, 2003 at 05:54 UTC
    You use commas to string together things for print or for multiple sub args. The semi-colon is needed to end a statement.

    The if that is causing the error is a new statement, so it needs to be preceeded by a semi-colon, or by the end of a block (closing curly).

    Michael

Re: Syntax errors galore, need a good debugging
by fglock (Vicar) on Jun 25, 2003 at 17:38 UTC

    '&nbsp;' x 100 saves some typing!

      Thank you so much for all the wisdom you've all shared with me on this one. The problem was solved when someone suggested I stored the JS into a variable and used the variable in the table itself (made the tables cleaner for debugging and for some reason the scalar runs differently than just the code did by itself *ponders that for a minute*). The problem is solved but from what you monks have showed me, there is still a lot of work that needs to be done with this.

      Normally I indent with PerlTidy and I appologize for not doing it before posting this node. It was used originally but since then lots of code was added and must have it more difficult for you to read and understand. For indents of printing as well, that usually gets fixed when I use PerlTidy and that may have helped solve the problem quicker (as one of you suggested).

      Thank you for sharing the differences between commas and semi colons, I'm sure that will come in handy on nearly all the scripts I write. Also, thank you for the shortcut for the &nbsp;, that'll make it look a lot cleaner :) Again, thank you for all your help. Perl is a tough language to get into but with people you like around it makes it possible to take a step forward.

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

Re: Syntax errors galore, need a good debugging
by WhiteBird (Hermit) on Jun 25, 2003 at 13:04 UTC
    Assuming that perhaps you haven't fixed this yet... My editor seems to prefer the following:
    qq(<SCRIPT LANGUAGE="JavaScript">), Tr( td(), td(submit), td("document.write('<form><input type=button value=\"Refresh\" onC +lick=\"history.go()\"></form>)" ), ), end_form(), hr(), qq(</script>) ); print "(<a href=\"log.pl\" target=\"new\">chat logs</a>)";