On Jul 6, 2006, at 6:26, Geetha Weerasooriya wrote:

Dear all,

When I was reading a Perl code I found the following line. Can u please
explain what it means?

!defined($rt_nearest) or $dh<$dist or next;

It means

  next unless !defined($rt_nearest) or $dh < $dist;

or, equivalently,

  next if defined($rt_nearest) and $dh >= $dist;

The trick in the original code is: the or operator returns as soon as some of the operands evaluates to true, if any. So if

  !defined($rt_nearest)

holds nothing to its right is evaluated. Otherwise we go for

  $dh < $dist

If it holds we are done, otherwise we evaluate the following operand

  next

which has the secondary effect of jumping to the next iteration somewhere. Some people dislike using boolean operators to control flow that way, some people don't.

-- fxn




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to