Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Reusing a variable declared earlier in the same scope

by Thilosophy (Curate)
on Apr 11, 2008 at 03:44 UTC ( #679615=note: print w/ replies, xml ) Need Help??


in reply to Reusing a variable declared earlier in the same scope

my $rows = $GetAssignmentID_sth->rows; if($rows > 0) { while (my ($AssignmentID, $UserCount) = $GetAssignmentID_sth-> fet +chrow_array() ) { push(@AssignmentIDs, $AssignmentID); } }

How about completely getting rid of the whole $rows part? It seems redundant (all it does is protect a while loop, that would not be executed anyway if there is no data to loop over), and error-prone ($sth->rows is not guaranteed to be the correct number of rows until you have fetched them all).

while (my ($AssignmentID, $UserCount) = $GetAssignmentID_sth-> fetchro +w_array() ) { push(@AssignmentIDs, $AssignmentID); }


Comment on Re: Reusing a variable declared earlier in the same scope
Select or Download Code
Replies are listed 'Best First'.
Re^2: Reusing a variable declared earlier in the same scope
by reluctant_techie (Novice) on Apr 14, 2008 at 15:30 UTC
    My purpose in testing whether or not any rows are returned is to prevent a situation where the final $AssignmentIDs variable point at an empty string. I am using this variable in my next SQL statement using the IN syntax. For example,
    SELECT ... FROM ... WHERE AssignmentID IN ($AssignmentIDs)
    This is all very helpful information though. Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-28 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls