home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!yale.edu!yale!gumby!destroyer!caen!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!network.ucsd.edu!nic!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: or puzzlement
- Message-ID: <1992Jul23.191243.9731@netlabs.com>
- Date: 23 Jul 92 19:12:43 GMT
- References: <BrtMFu.D0L@unx.sas.com>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 50
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <BrtMFu.D0L@unx.sas.com> kent@manzi.unx.sas.com (Paul Kent) writes:
- :
- :
- : hi,
- :
- : in some sub xx, i currently do the moral equivalent of:
- :
- : sub xx
- : {
- : opendir(D,$f) || warn "no dir $f" || return 1;
- : }
- :
- : which to my app is a non-fatal warning -- typically my outer loop
- : will do
- :
- : &sub() && next;
- :
- :
- :
- :
- : is it guarenteed that warn <stuff> will evaluate
- : to 0/false forcing the next thing in the or-sequence to be
- : evaluated, or am i just getting "lucky" (warn in the camel
- : book doesnt describe its result -- it may be grandfathered
- : elsewhere....)
-
- Actually, warn always returns true, but the reason the return is never
- evaluated is that "no dir $f" is always true, and warn is a list
- operator. You're getting lucky.
-
- What you really want to say is
-
- opendir(D,$f) || warn("no dir $f") && return 1;
-
- It works out nicely that && binds tighter than ||. On the other hand,
- it may be clearer to say
-
- opendir(D,$f) || do {warn "no dir $f"; return 1};
-
- or
-
- opendir(D,$f) || (warn("no dir $f"), return 1);
-
- Since warn returns 1, you should even be able to say
-
- opendir(D,$f) || return warn "no dir $f";
-
- That doesn't work for "next" though.
-
- Larry
-