blaze has asked for the wisdom of the Perl Monks concerning the following question:
products.db looks like:sub additem{ my $item = shift; my $quant = shift; if(!(-e $custid)){ open INF, ">$custid" or die "Couldnt create cart file: $!\n"; print INF ''; close INF; } open INF, "products.db" or die "Couldnt open db:$!\n"; my @products = <INF>; close INF; my ($itemno,$prod,$price,$desc); for(@products){ ($itemno,$prod,$price,$desc) = split(/\|/,$_); if($itemno == $item){ last; } } open CUSTCART, "$custid" or die "Couldnt read cart file: $!\n"; my @custchoices = <CUSTCART>; close CUSTCART; for(@custchoices){ chomp; my($in,$pr,$pri,$de,$qu) = split(/\|/,$_); if($in == $item){ #this is the start of my problems **** $qu++; open INF, ">$custid" or die "Couldnt update quantity: $!\n"; print INF "$in|$pr|$pri|$de|$qu|\n"; foreach my $line(@custchoices){ if($item !~ /^$in/){ print INF $line; } } close INF; print "Location: $url=view\n\n"; } } open CUSTID, ">$custid" or die "Couldnt open personal cart: $!\n"; print CUSTID "$itemno|$prod|$price|$desc|$quant|\n"; print CUSTID @custchoices; close CUSTID or die "Couldnt close file: $!\n"; sleep(1); print "Location: $url=view\n\n"; }
1002|One Dozen Yellow Roses|59.99|One dozen yellow roses with babys breath in a vase| 1003|One Dozen White Roses|59.99|Perfect for any occasion, one dozen white roses|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem comparing two variables
by graff (Chancellor) on Jan 03, 2003 at 03:17 UTC | |
|
Re: Problem comparing two variables
by gjb (Vicar) on Jan 03, 2003 at 02:21 UTC | |
by blaze (Friar) on Jan 03, 2003 at 02:30 UTC | |
by JamesNC (Chaplain) on Jan 03, 2003 at 06:51 UTC | |
|
Re: Problem comparing two variables
by pg (Canon) on Jan 03, 2003 at 02:45 UTC |