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

i have the following code:
#!d:\perl\bin\perl.exe -w use strict; use CGI qw(:all); my $cgi = new CGI; #Initialize phonebooks variables my $name = param('name'); my $surename = param('surename'); my $phone = param('phone'); my $selfphone = param('selfphone'); my $address = param('address'); my $location = param('location'); my $email = param('email'); print $cgi -> header, start_html(-title=>"Previewing $name ${surename}! entry", + -style=>{'src'=>'../htdocs/style.css'}). $cgi -> table ( #opening table tr({-align=>CENTER,-valign=>TOP}, [ #TR td(['Name', 'Surename','Phone']) ] #TR ) ); #Closing table $cgi->end_html;
and when im running the program i get the following error transliteration replacement not terminated at phbookad.pl line 23. the 23 line is ); #Closing table i cant figure out what the problem is. i have read the CGI.pm about tables but...

Replies are listed 'Best First'.
Re: cgi programming...
by pfaut (Priest) on Jan 10, 2003 at 15:38 UTC

    Since the table row tag (tr) collides with a perl's transliteration operator (tr///), you need to use Tr (notice the capital T) to generate table rows. This is all in the CGI pod.

    $cgi -> table ( #opening table Tr({-align=>CENTER,-valign=>TOP}, [ #TR td(['Name', 'Surename','Phone']) ] #TR ) ); #Closing table
    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: cgi programming...
by dragonchild (Archbishop) on Jan 10, 2003 at 15:53 UTC
    Or, even better, you could just continue using the object-oriented interface you started with and call $cgi->tr, $cgi->td, and $cgi->param instead.

    Oh - and use CGI; is sufficient if you're working with OO interfaces. You don't need the ":all" quantifier.

    And, I'm being serious here. Don't mix the procedural and OO interfaces. CGI can handle it, but that's because it's a helluva module. Most module authors aren't that nice, talented, motivated, and/or have that much time.

    ------
    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.

      that's a great tip about not mixing to different things (procedural and OO interfaces).
      Im still new in perl programming and generaly in programming.
      i've tried to get rid off the ":all" quantifer but i get the following error:
      Undefined subroutine &main::param called at phbookad.pl line 13.
      i think the solution is the $cgi->param you told me, but i dont (still) know how to use it. any tip would be usefull.
      thank you
        my $name = param('name');
        becomes
        my $name = $cgi->param('name');

        ------
        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.

Re: cgi programming...
by Fletch (Bishop) on Jan 10, 2003 at 15:38 UTC

    Perl is thinking that your call to CGI::tr() is actually the perl transliteration operator tr///. Try calling it as &tr( ... ) instead and see if that doesn't clear things up. And see perldoc perlop for more on tr///.

    Update: Or you could call the correct Tr as is mentioned below. See the section entitled NON-STANDARD HTML SHORTCUTS of perldoc CGI.

Re: cgi programming...
by rdfield (Priest) on Jan 10, 2003 at 15:39 UTC
    tr should be Tr.

    rdfield

Re: cgi programming...
by poj (Abbot) on Jan 10, 2003 at 18:18 UTC
    Also, you need to quote CENTER, TOP
    Tr({-align=>"CENTER",-valign=>"TOP"},
    and a dot not semi-colon here
    ). #Closing table

    poj
      why not use the semi-colon!? i get the same output, and with
      the perl -w switch no problem.
        You won't see it in the browser but check the source HTML and you will be missing the </body></html> tags.
        poj