Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!rbj From: rbj@uunet.UU.NET (Root Boy Jim) Newsgroups: comp.lang.perl Subject: Re: Checking if a variable is null Keywords: perl null Message-ID: <129570@uunet.UU.NET> Date: 19 Apr 91 22:51:41 GMT References: <483@cti1.UUCP> Organization: UUNET Communications Services, Falls Church, VA Lines: 25 In article <483@cti1.UUCP> kmeek@cti1.UUCP (Kevin Meek) writes: ?Is there a perl equivalent to the shell test operators -z and -n Yes, and it's builtin! The null string is false, and anything else (except the string "0" when coerced to a number) is true. ?I want to print a line if certain parts are not null. ? ?What I'm using is this: ? ?($a,$b,$c) = split(' '); ?if ( $a ne '' && $b ne '' ) { ? print $_; ?} You can say: if ("$a$b") { print; } Note that the default arg to print is $_. ?Is there a better way to check if a variable is null? ?i.e. print if -n $a How about "$a" && print "$a"; -- [rbj@uunet 1] stty sane unknown mode: sane