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

V

vikimun

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.
 
J

Johann Kappacher

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
 
J

Johann Kappacher

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
 
J

Johann Kappacher

Johann said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top