i am using cgi session to write a cart . here is the partial code. the problem is for loop will push mutiply times of same value if itemID is not exit in original array.
what i want is only push one times of value if itemid is a new value could any one here give some clue or show me the correct code? weather i could use "exists" to identify it? Thank you very much the cookie show below $D = {_SESSION_ID => 'de6426230428fcf1656dd0e79bc8cf88',_SESSION_ATIME => 1191284433,CART => [{name => '1_t-shirt',quantity => 7,price => '14.99',itemID => '1001'}],_SESSION_EXPIRE_LIST => {},_SESSION_REMOTE_ADDR => '192.168.1.170',_SESSION_CTIME => 1191284098}; use cgi::session %products = ( 1001=> [ "1_usr/bin/perl t-shirt", 14.99], 1002 => [ "2_just perl t-shirt", 21], 1003 => [ "3_shebang hat", 31], 1004 => [ "4_linux mug", 41], 1005 => [ "5_itme5", 51], # on and on it goes.... ); sub add_item { my ($cgi, $session, $products) = @_; # getting the itemID to be put into the cart my $itemID = $cgi->param("itemID") || &error ("$! ( No item specified ) "); # getting the current cart's contents: my $cart = $session->param("CART") || []; for my $product ( @{$cart} ) { if ( $product->{itemID} == $itemID) { updateitem_quantity } else ( push @{ $cart }, { itemID => $itemID, name => $products->{$itemID}->[0], price => $products->{$itemID}->[1], quantity => $quantity }; } #### # now store the updated cart back into the session $session->param( "CART", $cart ); # show the contents of the cart return display_cart($cgi, $session); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/