home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4916 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.6 KB

  1. 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
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: or puzzlement
  5. Message-ID: <1992Jul23.191243.9731@netlabs.com>
  6. Date: 23 Jul 92 19:12:43 GMT
  7. References: <BrtMFu.D0L@unx.sas.com>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 50
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <BrtMFu.D0L@unx.sas.com> kent@manzi.unx.sas.com (Paul Kent) writes:
  14. : hi,
  15. : in some sub xx, i currently do the moral equivalent of:
  16. : sub xx
  17. : {
  18. :   opendir(D,$f) || warn "no dir $f" || return 1;
  19. : }
  20. : which to my app is a non-fatal warning -- typically my outer loop
  21. : will do 
  22. :   &sub() && next;
  23. : is it guarenteed that warn <stuff> will evaluate
  24. : to 0/false forcing the next thing in the or-sequence to be
  25. : evaluated, or am i just getting "lucky" (warn in the camel
  26. : book doesnt describe its result -- it may be grandfathered
  27. : elsewhere....)
  28.  
  29. Actually, warn always returns true, but the reason the return is never
  30. evaluated is that "no dir $f" is always true, and warn is a list
  31. operator.  You're getting lucky.
  32.  
  33. What you really want to say is
  34.  
  35.     opendir(D,$f) || warn("no dir $f") && return 1;
  36.  
  37. It works out nicely that && binds tighter than ||.  On the other hand,
  38. it may be clearer to say
  39.  
  40.     opendir(D,$f) || do {warn "no dir $f"; return 1};
  41.  
  42. or
  43.  
  44.     opendir(D,$f) || (warn("no dir $f"), return 1);
  45.  
  46. Since warn returns 1, you should even be able to say
  47.  
  48.     opendir(D,$f) || return warn "no dir $f";
  49.  
  50. That doesn't work for "next" though.
  51.  
  52. Larry
  53.