Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Find odd/even elements of array

by keszler (Priest)
on Oct 09, 2011 at 21:33 UTC ( #930498=note: print w/ replies, xml ) Need Help??


in reply to Find odd/even elements of array

(I'm assuming that the two databases aren't linked, i.e. you can't join their tables. I'm also assuming that you're using DBI despite the mention of a fetchrow function. (DBI has fetchrow_arrayref, fetchrow_array, and fetchrow_hashref, but no just plain fetchrow.))

If you don't need the even ids from studentTable why not add a where clause to return only the odds?

If all you're doing with the studentTable in the 1st DB is loading an array why not use fetchall_arrayref?

my $studentInfo = $sth_queryID->fetchall_arrayref;

If you do need the even ids elsewhere you can easily skip them when querying the grades in the 2nd DB like this:

for my $studentInfo_row (@{$studentInfo}) { next unless $studentInfo_row->[0] % 2; ... }

You could also use a grep:

foreach my $studentInfo_row ( grep { $_->[0] % 2 } @{$studentInfo}) { ... }

update: fixed arrayref typos


Comment on Re: Find odd/even elements of array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-07-04 08:51 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 (58 votes), past polls