eric@lucii.org on Thu, 23 May 2002 17:36:14 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Perl question - references


I made a change (slight) to be sure that being in the quotes did not 
impact the interpretion of the variable name.

Line 5 now looks like this:


5        print "i: $i\tvalue: " .  @$BatchArray->[$i]  . "\n" ;

Still, no joy :-(

TIA.

Eric

On Thu, May 23, 2002 at 05:14:45PM -0400, eric@lucii.org wrote:
> I've been working on some perl code and I'm having trouble with
> references.  This situation is this:
> 
> I've got a list of batch numbers.  Unfortunately, there are some
> missing batches.  So, I may have batches (1, 2, 3, 5).
> 
> Now, if I am at the last batch (5) and I want to go back by one batch
> then I have to go to 3, not 4.  Simple subtraction won't work.
> 
> Here is the code that gets the array reference of batches from the
> database:
> 
> 1   $stH0 = $dbH0->prepare(
>            " SELECT batch_number " . 
>            "   FROM process_history " .
>            "  WHERE customer = '" . $CustomerNum . "'" .
>            "    AND batch_number > " . $LowLimitBatch .
>            "  ORDER BY batch_number " ) ;
> 2   $stH0->execute ;
> 3   ($BatchArray) = $stH0->fetchall_arrayref ;
> 
> Here, I want to print out the array index and the contents of that 
> array element:
> 
> 4   for (my $i = 0 ; $i < (@$BatchArray) ; $i++  ) {
> 5       print "i: $i\tvalue: @$BatchArray[$i])\n" ;
> 6   }
> 
> 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**

-- 
# 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**