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

Errors:
Thu Apr 3 06:34:42 2003 tags.pl: Bareword found where operator expected at tags.pl line 16, near ") Td" (error repeats for each TD)

I'm not looking for someone to fix my script for me, just to tell me what I'm doing wrong. This is my first attempt at using tables so if everything is out of whack, it's not just because my brain's on vacation.

Another question I have is why doesn't CGI.pm on cpan cover tables and why are there zero nodes on perlmonks about using tables in CGI?

print start_form(), table( Tr(Td( "Email Address: ") Td(textfield('usermail')), Tr(Td("Author: ") Td(textfield('author')), Tr(Td("Distributor: ") Td(textfield('distributor')), Tr(Td("Copyright: "),textfield('copyright')), Tr(Td("Abstract: ") Td(textfield('abstract')), Tr(Td("Keywords: ") Td(textarea(-name=>'keywords', -rows=>10, -columns=>50)), Tr(Td("Description: ") Td(textarea(-name=>'description', -rows=>10, -columns=>50))), Tr(Td("Robots: ") Td(popup_menu(-name=>'robots', -values=>['','index','noindex','follow','nofollow']))), Tr(Td("Distribution: ") Td(popup_menu(-name=>'distribution', -values=>['','local','global']))), Tr(Td("Language: ") Td(popup_menu(-name=>'language', -values=>['','EN','EN-GB','EN-US','ES','ES-ES','FR','IT +','JA','KO','DE']))); Tr(Td("Rating: ") Td(popup_menu(-name=>'rating', -values=>['','kids','general','mature','restricted']))) +, Tr(Td()Td(), Tr(Td()(Td(submit)), ), end_form(), hr;


"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: CGI Tables, yippie!!
by robartes (Priest) on Apr 03, 2003 at 13:01 UTC
    You need to seperate your Td() calls with commas. The way you are writing them causes the parser to interpret them as barewords (as evidenced by the error message).

    Update: That fixed, you also need to lowercase Td to td. The CGI.pm function is called td, not Td. Funnily enough Tr is called Tr, to avoid confusion with the transliteration operator.

    CU
    Robartes-

      Ok, I added the commas and the errors nearly disappeared! Thanks so much! But I have another problem though and since I'm really new to using CGI I don't exactly know how to debug things like this myself.

      The error I get this time is "Thu Apr 3 07:11:31 2003 tags.pl: syntax error at tags.pl line 39, near ");" ", any suggestions?

      It's kinda funny how it's Tr and td, but whatever works :)

      print start_form(), table( Tr(Td( "Email Address: "), Td(textfield('usermail')), Tr(Td("Author: "), Td(textfield('author')), Tr(Td("Distributor: "), Td(textfield('distributor')), Tr(Td("Copyright: "), Td(textfield('copyright')), Tr(Td("Abstract: "), Td(textfield('abstract')), Tr(Td("Keywords: "), Td(textarea(-name=>'keywords', -rows=>10, -columns=>50)), Tr(Td("Description: "), Td(textarea(-name=>'description', -rows=>10, -columns=>50))), Tr(Td("Robots: "), Td(popup_menu(-name=>'robots', -values=>['','index','noindex','follow','nofollow']))), Tr(Td("Distribution: "), Td(popup_menu(-name=>'distribution', -values=>['','local','global']))), Tr(Td("Language: "), Td(popup_menu(-name=>'language', -values=>['','EN','EN-GB','EN-US','ES','ES-ES','FR','IT +','JA','KO','DE']))), Tr(Td("Rating: "), Td(popup_menu(-name=>'rating', -values=>['','kids','general','mature','restricted']))) +, Tr(Td(), Td(submit)), end_form(), ), hr(); #### this is line 39


      "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
        Your first textarea is missing a ')' at the end.
        If you happen to use vim (or vi), the way to find such a thing is to put the cursor on the first (or last) '(' (or '{' or whatever) character and hit on '%'.
        In most cases this will jump to a place where the error is close.

        syntax error at tags.pl line 39, near ");" ", any suggestions?
        Your parentheses are unbalanced. On at least the first two "Tr" lines, you're opening more than you're closing.

        If your HTML is getting this complex, it might be time to look at HTML::Template or something similar.

        That's the one pita with CGI.pm tables - I love them, but you've got to keep bouncing on the "match bracket" key. It looks like this might be to do with a mis-matched bracket somewhere (but I don't see ');" "' on line 39 - puzzling)

        A minor point though (from a coding point of view, but important where your HTML validation is concerned) - you appear to have your 'start_form()' outside the table, while the 'end_form()' is inside it. Best to stick the end_form() outside too, so validators don't complain about your nesting.
        Cheers,
        Ben
        That's the reason why I always use print "<TR><TD>Blah blah blah</TD></TR>"; just because I know it works... :) (Yes, I know conceptually it's beautifull to reuse the tr & td code, but sometimes I feel that reinventing the wheel works best...)
Re: CGI Tables, yippie!!
by Thelonius (Priest) on Apr 03, 2003 at 13:02 UTC
    You need to put commas in between the elements. You also need to make sure each Tr is closed, add parentheses after hr(), and a few miscellaneous changes.
Re: CGI Tables, yippie!!
by Jaap (Curate) on Apr 03, 2003 at 13:00 UTC
    Looks like the function/subroutine Td you call does not exist. Therefore the perl interpreter thinks it is a "bare word", that has no meaning to the interpreter.

    Are you using some module to make the tables (like CGI.pm)?

    edit
    This was not the main problem, as robartes mentiones. A comma is missing before the td()
Re: CGI Tables, yippie!!
by cfreak (Chaplain) on Apr 03, 2003 at 15:46 UTC

    Many other people have answered your questions correctly, I however want to add that to avoid this mess its often easier to use a templating system where you separate your output from your Perl code. I personally use HTML::Template but there are several good ones out there.

    Chris

    Lobster Aliens Are attacking the world!
Re: CGI Tables, yippie!!
by Coruscate (Sexton) on Apr 03, 2003 at 21:39 UTC

    As for the formatting, I don't know if you'd find something more like this much easier to read:

    #!/usr/bin/perl -w use strict; use CGI::Pretty qw(:all); print header(), start_html('foo'), start_form(), table( Tr([ td([ 'Email Address:', textfield('usermail') ]), td([ 'Author:', textfield('author') ]), td([ 'Distributor:', textfield('distributor') ]), td([ 'Copyright:', textfield('copyright') ]), td([ 'Abstract:', textfield('abstract') ]), td([ 'Keywords:', textarea({ name => 'keywords', rows => 10, cols => 50 }) ]), td([ 'Description:', textarea({ name =>'description', rows => 10, cols => 50 }) ]), td([ 'Robots:', popup_menu({ name => 'robots', values => [ '', 'index', 'noindex', 'follow', 'nofollow' ] }) ]), td([ 'Distribution:', popup_menu({ name => 'distribution', values => [ '', 'local', 'global' ] }) ]), td([ 'Language:', popup_menu({ name => 'language', values => [ '', 'EN', 'EN-GB', 'EN-US', ' +ES', 'ES-ES', 'FR', 'IT', 'JA', 'K +O', 'DE' ] }) ]), td([ 'Rating:', popup_menu({ name => 'rating', values => [ '', 'kids', 'general', 'mature', 'restricted' ] }) ]), '', 'local', 'global' ] }) ]), td([ 'Language:', popup_menu({ name => 'language', values => [ '', 'EN', 'EN-GB', 'EN-US', ' +ES', 'ES-ES', 'FR', 'IT', 'JA', 'K +O', 'DE' ] }) ]), td([ 'Rating:', popup_menu({ name => 'rating', values => [ '', 'kids', 'general', 'mature', 'restricted' ] }) ]), th({ colspan => 2, valign => 'bottom' }, submit() ) ]) ), end_form(), hr();


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

      I really appreciate all of your help everyone, there is no way I could have learned as much perl as I did if it weren't for such an involved community like PerlMonks. Special thanks to Coruscate for teaching me how to make tables and then later how to fix things!

      Coruscate, I don't find your method easier to read than mine, probably because I've stared at my codes this way for quite a few hours and changing that would just end up confusing me even more. It's funny, my script has been rewritten three times by three different people in this past couple of days, sometimes I think some of you like to help more than you like to write your own scripts.

      Thanks again everyone, ++ for everyone.

      "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

        Ah, but there is a reason some of us prefer to rewrite other people's stuff. I don't have to come up with an idea or even a starting place for coding. It's easy to take the work someone else has done and redo it a different way. Of course, this doesn't hold true if the original code is obfuscated in certain ways. Then it's a nightmare to rewrite :P


        If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

Re: CGI Tables, yippie!!
by shotgunefx (Parson) on Apr 03, 2003 at 21:58 UTC
    You might find Tabular monstrosities from a couple of days ago helpful.

    -Lee

    "To be civilized is to deny one's nature."