Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: multiple conditions while loop

by kennethk (Abbot)
on May 17, 2012 at 15:45 UTC ( [id://971095]=note: print w/replies, xml ) Need Help??


in reply to multiple conditions while loop

It seems like the natural thing here is to pass your desired target handle as an argument to the subroutine rather than using a closure -- see perlsub for info on how to use subs in Perl. Your code might look like:
sub write1 { my $STH = shift; while ( @data=$STH->fetchrow_array() ) { print "<CENTER>"; print "<TR>"; print "<TD BGCOLOR='red'>"; print "<P ALIGN='CENTER'>"; print "<FONT COLOR='white'>"; } }

Alternatively, if you mean a closure that systematically goes over three previously defined statement handles, you can wrap your while loop in a foreach loop like:

sub write1 { foreach my $STH ($STH1, $STH2, $STH3) { while ( @data=$STH->fetchrow_array() ) { print "<CENTER>"; print "<TR>"; print "<TD BGCOLOR='red'>"; print "<P ALIGN='CENTER'>"; print "<FONT COLOR='white'>"; } } }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://971095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found