home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!gumby!destroyer!ubc-cs!dhami
- From: dhami@cs.ubc.ca (Mandeep S Dhami)
- Subject: Re: nuther perl-idiom question..
- Message-ID: <1992Sep2.001759.7304@cs.ubc.ca>
- Sender: usenet@cs.ubc.ca (Usenet News)
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- References: <Btx90n.BMG@unx.sas.com> <1992Sep1.232723.5911@news.eng.convex.com>
- Date: Wed, 2 Sep 92 00:17:59 GMT
- Lines: 24
-
- Tom Christiansen <tchrist@convex.COM> writes:
- >
- >In Perl, one often writes:
- >
- > $x = $foo || "default";
- >
-
- As long as you can be assured that $foo is not the string "0"!
- Try -
- $x="0";print '$y is ', $y=$x||"1",".\n";
- or even
- $x="0".""; ... # To force $x to be a string
-
- $y is 1.
-
-
- Hence I always use $x=defined($foo)?$foo:$bar;
-
- Mandeep.
- --
- __________________________________________________________________
- "I'm very brave generally," he went on in a low voice:
- "only to-day I happen to have a headache."
- -- Lewis Carroll
-