[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Help! Still Lost in Perl
****** message to minivend-users from Chris Rapier <rapier@psc.edu> ******
Mike Heins wrote:
>
> ****** message to minivend-users from Mike Heins <mikeh@minivend.com> ******
>
> Quoting Chris Rapier (rapier@psc.edu):
>
> > To do this I've written:
> >
> > [item-list]
> > [perl tables=products]
> > $ref = $Db->{products};
> > $column = "quantity";
> > $cart_sku = $Items->[$i]{'code'};
> > $cart_quantity = $Items->[$i]{'quantity'};
> > $db_quantity = $ref->field($column, $cart_sku);
> > $difference = $db_qauntity - $cart_quantity;
> > if ($difference < 0){
> > $Items->[$i]{'quantity'} = $db_quantity;
> > }
> > if ($difference > 0) {
> > $ref->inc_field($column, $cart_sku, -1);
> > }
> > if ($difference == 0) {
> > $ref->delete_record($cart_sku);
> > }
> > $i++;
> > [/perl]
> > [/item-list]
> >
>
> Questions, all rhetorical:
>
> 1. Where is $i coming from?
$i is an uninitialized variable used as a generic increment. When its
first called it obviously returns a 0 and is then incremented with the
$i++. Its kind of sloppy perl programming but relatively common for
throwaway vars like that.
> 2. Do you have Safe::Hole installed (assuming you are using SQL)?
Hurm. Shouldn't be necessary as I'm just using the default DB_File
database. Should it be?
Would this explain the way it fails everytime it hits a $ref-> ?
> 3. Have you seen your typo?
> Name "main::db_qauntity" used only once: possible typo at- line 6.
I'm not sure what you mean here. Could you elaborate?
Sorry to be dense about this.
Chris
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list