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

i have parameter $content='' and want insert cgi script and i get error like this :

print <<EOF; <thead class="flip-content"> <tr> <th width="20%"> Students id </th> <th class="numeric"> First Name </th> <th class="numeric"> Last Name </th> <th class="numeric"> Date Of Birth </th> <th class="numeric"> Year In </th> <th class="numeric"> Password </th> <th class="numeric"> Email </th> <th class="numeric"> Telepon </th> </tr> </thead> EOF while (my @row_array = $sth->fetchrow_array()) { print <<EOF; <tbody> <tr> <td> $row_array[0] </t +d> <td> $row_array[1] </t +d> <td> $row_array[2] </t +d> <td> $row_array[3] </t +d> <td> $row_array[4] </t +d> <td> $row_array[5] </t +d> <td> $row_array[6] </t +d> <td> $row_array[7] </t +d> </tr> </tbody> EOF } print"</table>";

Replies are listed 'Best First'.
Re: insert CGI script in single quotes.
by talexb (Chancellor) on Apr 25, 2016 at 16:01 UTC

    It looks like your intended post is supposed to be

    print <<EOF; <table> <thead class="flip-content"> <tr> <th width="20%"> Students id </th> <th class="numeric"> First Name </th> <th class="numeric"> Last Name </th> <th class="numeric"> Date Of Birth </th> <th class="numeric"> Year In </th> <th class="numeric"> Password </th> <th class="numeric"> Email </th> <th class="numeric"> Telepon </th> </tr> </thead> EOF while (my @row_array = $sth->fetchrow_array()) { print &lt;&lt;EOF; <tbody> <tr> <td> $row_array&#91;0&#93; </td> <td> $row_array<a href="?node=1">1</a> </td> <td> $row_array<a href="?node=2">2</a> </td> <td> $row_array<a href="?node=3">3</a> </td> <td> $row_array<a href="?node=4">4</a> </td> <td> $row_array<a href="?node=5">5</a> </td> <td> $row_array<a href="?node=6">6</a> </td> <td> $row_array<a href="?node=7">7</a> </td> </tr> </tbody> EOF } print"</table>\n";
    There's a reason for the Preview button -- it's to confirm that what you're posting is readable and has the minimum ;) number of spelling mistakes.

    Now on to reviewing your code.

    Update: Sorry, pressed submit too soon. It looks like you are missing the part that pulls the data from the database -- you need something like $row_array->{$name_of_data_element_goes_here} in your table cell.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      > There's a reason for the Preview button ...

      > Update: Sorry, pressed submit too soon. ...

      LOL ;-P

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      sorry, i'm a newbie sir :). thank's for the suggest :)
Re: insert CGI script in single quotes.
by NetWallah (Canon) on Apr 25, 2016 at 16:42 UTC
    Please use <code> tags to post perl code at this site. See Markup in the Monastery.

    If the code you used looks like:

    while (my @row_array = $sth->fetchrow_array()) { print <<EOF; <tbody> <tr> <td> $row_array[0] </td> <td> $row_array[1] </td> <td> $row_array[2] </td> ... </tr> </tbody> EOF }
    then the only way you could have got the output you did is if the database actually contained the record
    $row_array[0] $row_array[1] $row_array[2] ...
    So - it would help if you posted brief DB content information as well.

            This is not an optical illusion, it just looks like one.

      i have try some suggested by friend, and i got a same problem. the real problem is, how can i use a while function in single quotes. my db have contained a record, but i have fail to call it in single quotes function. :)

        What do you mean by "single quotes function"? It will help us if you can post the problematic loop with the function, ideally together with the data you want to pass to it. Something like the following:

        #!perl -w use strict; # This would come from the database my @data = ( ['Hello','World',1,2,3,4,5], ['Hello','Pakeidoprek,6,7,8,9,0], ); while( my $item = shift @data) { ... problematic part ... };
        The code you posted in your original node works fine.

        It sounds like you want it to continue to work with a single-quoted "heredoc", i.e.:

        print <<'EOF';
        By doing that, you are defeating interpolation.

        May I suggest an alternative , more efficient (for the programmer) syntax to get the results you want, while avoiding the "heredoc" syntax that you are having trouble with :

        use CGI; my $q = CGI::->new(); print $q->start_table($q->caption("table Caption")), "\n", $q->thead({-class=>"flip-content"}, $q->Tr($q->td({-width=>"20%"},"Students id") , map {$q->td({-class=>"numeric"}, $_). "\n"} ("First Name", "Last Name", "Date Of Birth", "Year In", "Password", "Email","Telepon") )), "\n", $q->start_tbody(),"\n"; while (my @row_array = $sth->fetchrow_array()){ print $q->Tr( map {$q->td($_) . "\n"} @row_array ),"\n"; } print $q->end_tbody(),"\n",$q->end_table(),"\n";
        There are better alternatives if you use one of the "template" modules, but this should get you started.

                This is not an optical illusion, it just looks like one.