SSC_perl
2014-09-17 00:37:46 UTC
I just ran across something puzzling. Why are these two statements not equivalent when it comes to warnings?
if ($item->{'optionprice'}) {
$item->{'unitprice'} += $item->{'optionprice'};
}
and
$item->{'unitprice'} += $item->{'optionprice'} if ($item->{'optionprice'});
Given the following values:
$item->{'unitprice'} = '12.16';
$item->{'optionprice'} = '';
the 2nd statement returns an "Argument '' isn't numeric in addition (+)" warning, while the 1st one doesn't. I thought I read where Peal reads a statement like the 2nd one from right to left. It looks like it doesn't, since $item->{'optionprice'} is evaluated in spite of the 'if'. Am I mistaken?
Perl 5.10.1
Thanks,
Frank
SurfShop shopping cart is now open source...
http://www.surfshopcart.com/
Setting up shop has never been easier!
Follow us on GitHub!
https://github.com/surfshopcart/surfshop
if ($item->{'optionprice'}) {
$item->{'unitprice'} += $item->{'optionprice'};
}
and
$item->{'unitprice'} += $item->{'optionprice'} if ($item->{'optionprice'});
Given the following values:
$item->{'unitprice'} = '12.16';
$item->{'optionprice'} = '';
the 2nd statement returns an "Argument '' isn't numeric in addition (+)" warning, while the 1st one doesn't. I thought I read where Peal reads a statement like the 2nd one from right to left. It looks like it doesn't, since $item->{'optionprice'} is evaluated in spite of the 'if'. Am I mistaken?
Perl 5.10.1
Thanks,
Frank
SurfShop shopping cart is now open source...
http://www.surfshopcart.com/
Setting up shop has never been easier!
Follow us on GitHub!
https://github.com/surfshopcart/surfshop
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/