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

Discussion in 'Perl Misc' started by vikimun@gmail.com, Apr 6, 2008.

  1. Guest

    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.
    , Apr 6, 2008
    #1
    1. Advertising

  2. 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
    Johann Kappacher, Apr 6, 2008
    #2
    1. Advertising

  3. 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
    Johann Kappacher, Apr 6, 2008
    #3
  4. 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!
    Johann Kappacher, Apr 6, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    357
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,490
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    377
    thomson
    Jun 20, 2005
  4. Oodini
    Replies:
    1
    Views:
    1,762
    Keith Thompson
    Sep 27, 2005
  5. Alex Hall
    Replies:
    5
    Views:
    226
    Lawrence D'Oliveiro
    May 11, 2010
Loading...

Share This Page