in reply to Re: insert CGI script in single quotes.
in thread insert CGI script in single quotes. [SOLVED]

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. :)
  • Comment on Re^2: insert CGI script in single quotes.

Replies are listed 'Best First'.
Re^3: insert CGI script in single quotes.
by Corion (Patriarch) on Apr 26, 2016 at 09:09 UTC

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

      i have parameter content in my modules, and i want to use it in my web page to insert cgi script. the sample of codes like this :

      #subroutines sub content; #parameter in modules template my ($self,$content=,) = @_; #scalar placing content my $html = ''; #body content $html .='<div>'; $html .=''.$content.''; $html .='</div>'; #
      # i used the parameter in my web content with single quotes .. print MODULES::template->content('XXX'); ..

      the XXX is 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] </td> <td> $row_array[1] </td> <td> $row_array[2] </td> <td> $row_array[3] </td> <td> $row_array[4] </td> <td> $row_array[5] </td> <td> $row_array[6] </td> <td> $row_array[7] </td> </tr> </tbody> EOF } print"</table>";

        Then don't print the table, return it:

        my $result = <<EOF; 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()) { $result .= <<EOF; <tbody> <tr> <td> $row_array[0] </td> <td> $row_array[1] </td> <td> $row_array[2] </td> <td> $row_array[3] </td> <td> $row_array[4] </td> <td> $row_array[5] </td> <td> $row_array[6] </td> <td> $row_array[7] </td> </tr> </tbody> EOF } $result .= "</table>"; return $result
Re^3: insert CGI script in single quotes.
by NetWallah (Canon) on Apr 26, 2016 at 16:19 UTC
    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.

      wow it's great format. i will try it sir :)