in reply to Re: Re: Re: Image::Magick resize question
in thread Image::Magick resize question

my $y = int rand 10 or die; This will work correctly since or binds losely. 10 is regarded as a parameter to rand which is regarded as a parameter to int; the result will be tested with or and die 1 out of 10 times. my $y = int rand 10 || die; This will never die since || binds tightly and causes 10 || die to be evaluated first. The result of that expression is then passed to rand as a parameter, and so on.

Sometimes, very rarely, you actually want the tight binding rather than the lose, however.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: or vs precedence issue
by emilford (Friar) on Jun 09, 2002 at 15:31 UTC
    Cool! I was quite unaware of the difference between || and or. If it makes that much of a difference, I'll start using or in place of || when checking return errors. Thanks for the reply, the information was very useful.

      Nononono. Not everywhere. Everywhere it belongs. Neither one is "the right one". Please take the time to understand exactly why they each work the way they do.

      Here's a hint: everything you can do with the one, you can also do with the other, as long as parens regulate precedence.

      Makeshifts last the longest.