Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: multiple conditions while loop

by kennethk (Monsignor)
on May 17, 2012 at 15:45 UTC ( #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.


Comment on Re: multiple conditions while loop
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2014-10-22 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls