Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Shortcut for if(defined($var) && $var ne "") ?

Reply
Thread Tools

Shortcut for if(defined($var) && $var ne "") ?

 
 
vikimun@gmail.com
Guest
Posts: n/a
 
      04-06-2008
Is there shorter equivalent of if(defined($var) && $var ne "")
that doesn't fall for the "0" case, and doesn't produce warning with -
w ?

Thanks
V.M.
 
Reply With Quote
 
 
 
 
Johann Kappacher
Guest
Posts: n/a
 
      04-06-2008
wrote:
> Is there shorter equivalent of if(defined($var) && $var ne "")
> that doesn't fall for the "0" case, and doesn't produce warning with -
> w ?
>
> Thanks
> V.M.

Hmm,

if (length $var) ....

--jk
 
Reply With Quote
 
 
 
 
Johann Kappacher
Guest
Posts: n/a
 
      04-06-2008
Sorry,

it will produce warnings if it is not initialized.
If you want to avoid warnings you must use defined().

perl 5.10 introduces the defined-or Operator.
=> This is your solution.

--jk
 
Reply With Quote
 
Johann Kappacher
Guest
Posts: n/a
 
      04-06-2008
Johann Kappacher wrote:
> Sorry,
>
> it will produce warnings if it is not initialized.
> If you want to avoid warnings you must use defined().
>
> perl 5.10 introduces the defined-or Operator.
> => This is your solution.
>
> --jk


.... but no, you need a defined-and operator!
I give up, this exercise is futile!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shortcut to SP2's "Choose a wireless network" dialog box? =?Utf-8?B?TWljaGFlbCBBLiBMb3dyeQ==?= Wireless Networking 4 02-14-2008 05:48 PM
Disable service shortcut =?Utf-8?B?ZG9vZ2Vl?= Wireless Networking 0 10-04-2005 05:39 AM
Shortcut, And Re-Directing Of Shortcut Quest. ? Robert11 Computer Support 1 12-30-2004 03:13 PM
Can't figure out how to put shortcut on desktop in FireFox JohnF Firefox 3 09-15-2004 01:22 PM
Firefox--shortcut errors Flatus Ohlfahrt Firefox 5 07-15-2004 03:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57