Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930498]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-04-24 16:50 GMT
Find Nodes?
    Voting Booth?