Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, my code is
print "usage_grpinf[2] :$usage_grpinf[2]\n"; if ( $usage_grpinf[2] eq "") { print "event_date valid2\n"; } output is -- Call_UsingHash12.pl usage_grpinf[2] :
Actually the element is empty but message "event_date valid2" is not getting printed. can any body help me in this?

Replies are listed 'Best First'.
Re: how can i check an array element as empty or not
by susanti13 (Novice) on Jul 21, 2009 at 06:06 UTC
    $usage_grpinf[2] may be undefined or contains spaces/characters.

    add "use strict" or/and "use warnings". If $usage_grpinf[2]is undefined, it will give such warnings when you execute the program.

    also try printing $usage_grpinf[2] enclosed in brackets so you'll know if it contains spaces or newlines i.e.
    print "usage_grpinf[2] : |$usage_grpinf[2]|\n";
      you could also
      C:\>perl -le print(chr(9)) |cat -v ^M C:\>perl -le print(chr(9)) |od -tax1 0000000 ht cr nl 09 0d 0a 0000003 C:\>perl -le print(chr(9)) |hexdump 00000000: 09 0D 0A - | | 00000003;
      Thanks all, It had a tab as the element :)
Re: how can i check an array element as empty or not
by ikegami (Patriarch) on Jul 21, 2009 at 05:41 UTC

    Then perhaps it only *appears* empty (e.g. it contains a space or a newline).