|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: Perl question - references
|
Kyle:
YES! That was the clue I needed. Thanks!
I just used @$BatchArray[$i]->[0]
^
or I got mighty complaints from perl.
Thanks again.
Eric Lucas
On Thu, May 23, 2002 at 05:20:23PM -0400, Kyle R . Burton wrote:
> > I've been working on some perl code and I'm having trouble with
> > references. This situation is this:
> >
[[CUT]]
>
> I think fetchall_arrayref returns an array of arrays:
>
> print "i: $i\tvalue: ",$BatchArray[$i]->[0],"\n";
>
> Since you only selected 1 column, there will only be 1 value in the
> inner array.
>
> DBI aslo has a selectall_arrayref (similar to fetchall_arrayref, but it
> does the prepare for you), and selectcol_arrayref (wich gives you a 1
> dimensional array):
>
> my $sql = q{
> SELECT batch_number
> FROM process_history
> WHERE customer = ?
> AND batch_number > ?
> ORDER BY batch_number
> };
> my $resultSet = $dbH0->selectcol_arrayref(
> $sql,
> undef, # no statement params
> $CustomerNum, # bind var1
> $LowLimitBatch # bind var2
> );
>
> unless( $resultSet ) {
> confess "Error executing sql: '$sql' ",$dbH0->errstr(),"\n";
> }
>
> for( my $i = 0; $i < @{$resultSet}; ++$i ) {
> print "i: $i\tvalue: $resultSet->[$i]\n" ;
> }
>
> If you use selectall_arrayref, then it's a 2 dimensional array:
>
> for( my $i = 0; $i < @{$resultSet}; ++$i ) {
> print "i: $i\tvalue: $resultSet->[$i]->[0]\n" ;
> }
>
> HTH
>
> Kyle
>
> > As you can see on line 5, I use @$BatchArray[$] to get the element.
> > Unfortunately, I see this when I run it:
> >
> > i: 1 value: ARRAY(0x8202900))
> > i: 2 value: ARRAY(0x8202924))
> > i: 3 value: ARRAY(0x820cab4))
> > i: 4 value: ARRAY(0x820cad8))
> > i: 5 value: ARRAY(0x820cafc))
> > i: 6 value: ARRAY(0x820cb20))
> >
> > I would have expected this....
> >
> > i:0 value: 1
> > i:1 value: 2
> > i:2 value: 3
> > i:3 value: 5
> > i:4 value: 6
> >
> > I even tried $BatchArray->[$i]
> > no luck.
> >
> > Any help is greatly appreciated.
> >
> >
> > Eric
> > --
> > # Eric Allan Lucas
> > #-------------------
> > # Support Ken Krawchuk - Libertarian for Governor of Pennsylvania!
> > # Find out how YOU can help -> http://www.kenk.org
> > #-------------------
> > **Majordomo list services provided by PANIX <URL:http://www.panix.com>**
> > **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
>
> --
>
> ------------------------------------------------------------------------------
> Wisdom and Compassion are inseparable.
> -- Christmas Humphreys
> mortis@voicenet.com http://www.voicenet.com/~mortis
> ------------------------------------------------------------------------------
> **Majordomo list services provided by PANIX <URL:http://www.panix.com>**
> **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
--
# Eric Allan Lucas
#-------------------
# Support Ken Krawchuk - Libertarian for Governor of Pennsylvania!
# Find out how YOU can help -> http://www.kenk.org
#-------------------
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|