home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5667 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.0 KB  |  36 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!gumby!destroyer!ubc-cs!dhami
  3. From: dhami@cs.ubc.ca (Mandeep S Dhami)
  4. Subject: Re: nuther perl-idiom question..
  5. Message-ID: <1992Sep2.001759.7304@cs.ubc.ca>
  6. Sender: usenet@cs.ubc.ca (Usenet News)
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. References: <Btx90n.BMG@unx.sas.com> <1992Sep1.232723.5911@news.eng.convex.com>
  9. Date: Wed, 2 Sep 92 00:17:59 GMT
  10. Lines: 24
  11.  
  12. Tom Christiansen <tchrist@convex.COM> writes:
  13. >
  14. >In Perl, one often writes:
  15. >
  16. >    $x = $foo || "default";
  17. >
  18.  
  19. As long as you can be assured that $foo is not the string "0"!
  20. Try -
  21.   $x="0";print '$y is ', $y=$x||"1",".\n";
  22. or even 
  23.   $x="0".""; ... # To force $x to be a string
  24.  
  25. $y is 1.
  26.  
  27.  
  28. Hence I always use $x=defined($foo)?$foo:$bar;
  29.  
  30. Mandeep.
  31. --
  32. __________________________________________________________________
  33. "I'm very brave generally," he went on in a low voice:
  34. "only to-day I happen to have a headache."
  35.                                       -- Lewis Carroll
  36.