Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: an odd if then statement

by HyperZonk (Friar)
on Jul 23, 2001 at 21:33 UTC ( [id://99094]=note: print w/replies, xml ) Need Help??


in reply to an odd if then statement

One of the big problems here is that == is used for number equality, not string equality. Use
if ($discount eq '40+15')
To do what you are attempting in this line.

However, because things may change, this is probably not the best way to approach what you are trying to do. What if someday you need to be able to evaluate '35+15' or some other such thing? If the discounts are always going to appear in this format, you could do something like:
@discount = split(/\+/, $discount); $discount = 1; foreach (@discount) { $discount*=$_/100; } $discount*=100;

and then do your quantity calculations.

-HZ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://99094]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-24 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found