cgi.pm and loop statements

Alan Stewart astewart at spawar.navy.mil
Tue Sep 12 17:23:50 CDT 2000


~sdpm~
On 12 Sep 00, at 14:48, Vasquez, Mike wrote:

>~sdpm~
>I am having problems trying to do a for loop statement using CGI.PM
>
>I have a nested table and I want to do a for loop statement  and print the
>array   Here's a sample of the syntax.  I am new to this.  Any help would be
>appreciated.
>. . .
>	print $q->start_table(),
>               $q->TR(
>	      $q->td(
>                     $q->start_table(),
>                        $q->TR(
>                           $q->td(($q->b('RATE')),
>                              $q->td(
>                                 for ($i=0; $i<=4; $i++){   #### I get an

At this point Perl is looking for a string parameter for $q->td(), not a Perl 
statement like "for". You can call a sub that returns a string here.

Also, I think you want the loop wrapped around the inner $q->td(), not inside 
of it. I might do this:

	print $q->start_table(),
                 $q->TR(
	      $q->td(
                    $q->start_table(),
                        $q->TR(
                           $q->td(($q->b('RATE')),
                              sub {my $speeds;
                                      for ($i=0; $i<=4; $i++) {
                                           $speeds .= $q->td($speed[$i]);
                                      }
                                      return $speeds;
                               },
                          ), # end row

The anonymous sub returns a string of all speeds, each with <td></td> 
markup, which is a parameter to $q->TR, which is a parameter to print.

BTW, the for loop looks like C (blechh), not Perl, but I left it that way. 
Probably should be:

                                      for (@speed) {
                                           $speeds .= $q->td($_);


---------------------------------------------------------------
Alan Stewart          )-[]-(           Electronics Engineer
Code D621           ~        ~         Network Operations
SPAWARSYSCEN       ~          ~  \     Satellite Communications
53560 Hull St   ( ~            ~  )    tel (619)524-3625
San Diego,CA  __|___             /|    fax (619)524-2607
92152-5001   ^\____/^^^^^^\    __| |_  astewart at spawar.navy.mil
------------^^^^^^^^^^^^^^^\__|______|_------------------------
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list