Dave K wrote:
Hello - I am new to Perl, and looking for some much needed direction.
I am trying to get a basic formula in place (within an existing IF
statement) that will serve to increase my price (i.e., "$new_price")
by the following formula:
=PRICE divided by 0.8 plus 15
In other words, if the Price is equal to 3, the results of the
$new_price should be 18.75. And if the price is equal to 5, then the
$new_price should be equal to 21.25.
The script that I am trying to alter is shown below. Can someone
possibly let me know how I can alter the below script (which I believe
would mean to alter the line that reads $new_price = $o_list[2]-
{price};) so that the new price would would work as described above?
Also, just a layman's explanation of the syntax shown below would be
greatly helpful. I am trying to understand what the "-="
$x -= $y;
Is short for:
$x = $x - $y;
It is borrowed from the C programming language.
and the "->"
That is the dereference operator.
perldoc perlop
perldoc perlref
perldoc perldsc
and the "?" characters represent.
? : is the conditional operator.
my $x = $a > $b ? $y : $z;
Is equivalent to:
my $x;
if ( $a > $b ) {
$x = $y;
}
else {
$x = $z;
}
Thanks for any suggestions or guidance.
#
if ( @o_list ) {
if ( defined ( $o_list[2] ) ) {
$new_price = $o_list[2]->{price};
$new_price -= $new_price<= 0 ? $new_price - .01 : 0;
}
}
if ( @o_list && defined $o_list[ 2 ] ) {
$new_price = $o_list[ 2 ]{ price } / 0.8 + 15;
}
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/