in reply to Re: or or
in thread or or

>or is almost always what you mean in these cases.

This is largely a matter of programming style, and the nature of the project, not something inherent to Perl. I find myself using || about ten times as often as or.

Because most of my program data is non-zero, I find myself using a lot of things like:

$param = $value || $default;

OTOH, maybe I am using too many if/else blocks...

 

Paris Sinclair    |    4a75737420416e6f74686572
pariss@efn.org    |    205065726c204861636b6572
I wear my Geek Code on my finger.

Replies are listed 'Best First'.
RE: RE: Re: or or
by ahunter (Monk) on Jul 09, 2000 at 01:57 UTC
    I'm not sure what you mean here - you provide a classic example of where or is most certainly not appropriate (as if you use it, $param will never get the value of $default).

    That is,

    $param = $value or $default;
    Will result in $param always getting the value of $value, never $default. or has lower precedence than = (in fact it has the absolute lowest precedence of all the operators). Maybe it was just me not being clear, though. You should always use 'or' where what you really want to say is:
    ($param=$value) or die "darn"
    That is, you don't want the value of die to get assigned to $param (yeah, die doesn't return very often. But it forces scalar context, which is why the alternative is a Bad Thing). Using or, your example would have to be:
    $param=$value or $param=$default
    So it's not always a matter of style.

    Andrew.

      I don't think you understood my point. My point was, TMTOWTDI, so depending on which stucures you build your program with, one or the other will be more commonly useful.

      Sorry to have been so unclear.

      But I'm not sure what your point is about the code, yes I gave an example that is not appropriate with or, it illustrates that your algorithm logic is the determining factor in which operator is more common.

       

      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.