Combining multiple arrayrefs

Combining multiple arrayrefs

am 12.11.2005 18:08:06 von mickalo

Hello,

this maybe more of a perl question then dbi, but not sure exactly how to
approach this. I have 4 separate queries:

$sql = |QUERY1|;
$arrayref_articles = $dbh->selectall_arrayref($sql);
$sql = |QUERY2|;
$arrayref_directory = $dbh->selectall_arrayref($sql);
$sql = |QUERY3|;
$arrayref_jobs = $dbh->selectall_arrayref($sql);
$sql = |QUERY4|;
$arrayref_insets = $dbh->selectall_arrayref($sql);

what I need to do is combine all 4 of these selectall_arrayref() into one array
ref and loop thru all the results. IE:

$allarrayref =
[$arrayref_articles,$arrayref_jobs,$arrayref_directory,$arra yref_insets];

But I don't think this approach works. what is the best way to combine all of
them into one arrayref so the single $allarrayref contains all results of the
combined arrayrefs ??

TIA

--
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re: Combining multiple arrayrefs

am 12.11.2005 18:47:28 von dm.list

Mike,

The statement should be

$allarrayref =
[@$arrayref_articles,@$arrayref_jobs,@$arrayref_directory,@$ arrayref_insets];


See perlref (http://search.cpan.org/dist/perl/pod/perlref.pod).

You might alternatively want to consider doing just a single query:

$allarrayref_articles = $dbh->selectall_arrayref("
($sql1) UNION ALL
($sql2) UNION ALL
($sql3) UNION ALL
($sql4)
");

--davidm

Mike Blezien wrote:

> Hello,
>
> this maybe more of a perl question then dbi, but not sure exactly how
> to approach this. I have 4 separate queries:
>
> $sql = |QUERY1|;
> $arrayref_articles = $dbh->selectall_arrayref($sql);
> $sql = |QUERY2|;
> $arrayref_directory = $dbh->selectall_arrayref($sql);
> $sql = |QUERY3|;
> $arrayref_jobs = $dbh->selectall_arrayref($sql);
> $sql = |QUERY4|;
> $arrayref_insets = $dbh->selectall_arrayref($sql);
>
> what I need to do is combine all 4 of these selectall_arrayref() into
> one array ref and loop thru all the results. IE:
>
> $allarrayref =
> [$arrayref_articles,$arrayref_jobs,$arrayref_directory,$arra yref_insets];
>
> But I don't think this approach works. what is the best way to combine
> all of them into one arrayref so the single $allarrayref contains all
> results of the combined arrayrefs ??
>
> TIA
>

Re: Combining multiple arrayrefs

am 12.11.2005 19:11:49 von mickalo

David,

Ah yea, I knew I missed something, the "@" was what I was missing. I try your
alternative you suggested see how it works.

Thx's abunch.. big help :)

Mickalo

David Manura wrote:
> Mike,
>
> The statement should be
>
> $allarrayref =
> [@$arrayref_articles,@$arrayref_jobs,@$arrayref_directory,@$ arrayref_insets];
>
>
> See perlref (http://search.cpan.org/dist/perl/pod/perlref.pod).
>
> You might alternatively want to consider doing just a single query:
>
> $allarrayref_articles = $dbh->selectall_arrayref("
> ($sql1) UNION ALL
> ($sql2) UNION ALL
> ($sql3) UNION ALL
> ($sql4)
> ");
>
> --davidm
>
> Mike Blezien wrote:
>
>> Hello,
>>
>> this maybe more of a perl question then dbi, but not sure exactly how
>> to approach this. I have 4 separate queries:
>>
>> $sql = |QUERY1|;
>> $arrayref_articles = $dbh->selectall_arrayref($sql);
>> $sql = |QUERY2|;
>> $arrayref_directory = $dbh->selectall_arrayref($sql);
>> $sql = |QUERY3|;
>> $arrayref_jobs = $dbh->selectall_arrayref($sql);
>> $sql = |QUERY4|;
>> $arrayref_insets = $dbh->selectall_arrayref($sql);
>>
>> what I need to do is combine all 4 of these selectall_arrayref() into
>> one array ref and loop thru all the results. IE:
>>
>> $allarrayref =
>> [$arrayref_articles,$arrayref_jobs,$arrayref_directory,$arra yref_insets];
>>
>> But I don't think this approach works. what is the best way to combine
>> all of them into one arrayref so the single $allarrayref contains all
>> results of the combined arrayrefs ??
>>
>> TIA