sub add_item { my @item_ref; my @cart_ref; my ($dbh, $cart_ref, $item_id, $qty, $color) = @_; # If the item isn't already in the cart, look it up from the database # and store it in the cart as a new entry with a quantity of zero. if (!exists ($cart_ref->{$item_id})) { my $sth = $dbh->prepare ("SELECT item_id, description, category, price, picture, thumbnail, mime_type, color FROM catalog_pet WHERE item_id = ?"); $sth->execute ($item_id); my $item_ref = $sth->fetchrow_arrayref (); $sth->finish (); return if !defined ($item_ref); # this shouldn't happen... @cart_ref->[0] = {}; # create new entry, indexed by item ID @cart_ref->[1] = $item_ref->{description}; @cart_ref->[3] = $item_ref->{price}; @cart_ref->[8] = 1; } @cart_ref->[8] = $qty; @cart_ref->[7] = $color; push (@cart_ref, @item_ref); }