I want numeric, Not string.

How can I convince use CGI qw(:standard) that $price = param("cost") is intended as a number and not a string?
Who is Participating?
alamoConnect With a Mentor Commented:
Doesn't look to me like $price is the problem at all. Here's what I see:

Problem 1: verify.cgi calls cartx.cgi with the piece to add and the price. cartx.cgi is looking for (param('action') eq 'Add'), and for param('new_items') to contain the items to add. (Both of which are true when cartx.cgi calls itself to edit the cart). You need verify.cgi to use the same fields, or else add code to cartx.cgi to check param('piece') so they are in sync. Since verify.cgi doesn't set an action cartx.cgi doesn't add it. cartx.cgi.

Problem 2: %pce is supposed to holds the number of items, the comment says so -
# The cookie formatted as an associative array
# mapping item name to the number of items.

But then when you add an item $_ to %pce you use:

$pce{$_} = $pce + $price;

Problem 2a: $pce is blank, you meant to use $pce{$_} there.
Problem 2b: Since %pce holds *quantity* not price, you really want
$pce{$_} += $quantity;

What you then need to do is as you print the table, look up the price in cartx.dat and print and total it from there. You certainly don't want to depend on saving the price in a cookie or getting it from a form, since the user could theoretically edit the html to set the price to whatever he wants.

As best I can tell you are setting the cookie and reading it back correctly, the problem is how you set %pce.
Does it now believe it it not intended as a number?
budginAuthor Commented:
It keeps returning a value of zero.
in the start_html() part of the program, I have (print $price;) and it returns "25", but it wont add it to the cookie.
If I use ($price = 25;) it adds it, but I need it to read a value from another form.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

If (print $price;) is really returning with the quotes around the number, then those non-numeric characters would make it have a value of zero when adding.
You could remove all non-digits from $price with something like
$price =~ s/\D//g;
budginAuthor Commented:
I thank you very much for your help. I would appreciate it if you would take a look at http://www.budmar.com/budcart.htm  I have links to code in the CGIs.
What are you adding $price to?
budginAuthor Commented:
Thanks Much to ozo and alamo. I see what I was doing. Without a need for a quanity feature when selling antiques, I was trying to alter that parameter, instead of using gumption. I am starting form scratch, and being patient.
All Courses

From novice to tech pro — start learning today.