home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!cs.utexas.edu!uwm.edu!ogicse!reed!romulus!merlyn
- From: merlyn@romulus.reed.edu (Randal L. Schwartz)
- Newsgroups: comp.lang.perl
- Subject: Re: or puzzlement
- Message-ID: <MERLYN.92Jul23070028@romulus.reed.edu>
- Date: 23 Jul 92 14:00:31 GMT
- Article-I.D.: romulus.MERLYN.92Jul23070028
- References: <BrtMFu.D0L@unx.sas.com>
- Sender: news@reed.edu (USENET News System)
- Organization: Reed College
- Lines: 43
- In-Reply-To: kent@manzi.unx.sas.com's message of 23 Jul 92 02:47:54 GMT
-
- In article <BrtMFu.D0L@unx.sas.com> kent@manzi.unx.sas.com (Paul Kent) writes:
-
- i know i can do:
-
- opendir(D,$f) || do
- { warn "no $f";
- return 1;
- };
-
-
- but that seems ugly. is there a better idiom for things like
-
- dothis || warn_and_return
- dothis || warn_and_next
-
- In the stuff you're doing, you could just go:
-
- open(...) || warn " xxx ";
-
- because the return value will be the last value executed, so you'll
- get a "1" on a successful "open", and a 0 on a "warn" (presuming that
- warn does indeed return 0 always). Larry will have to comment on
- whether to trust that behavior.
-
- If you need to return a 0 from the middle of a routine (using return),
- I've been known to do things like:
-
- warn "oops!", return 0 unless open(...);
-
- *or*, if you can guarantee the 0 value of warn, you could even do this:
-
- open(...) || return warn "bad news!"
-
- Sure, it looks weird, but it's perlish!
-
- (It's funny, but while I was constructing my JAPH, I discovered that
- *my* warn is returning 1. Are you *sure* you are getting 0?)
-
- warn "Just another Perl hacker,\n" || die;
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
- cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
-