in reply to Checking for blank string

Hi Himaja,

Could you show us your hash with Data::Dumper? E.g. use Data::Dumper; print Dumper(\%hash);

You check for definedness with defined, e.g. if (!defined $hash{key}). One way to check for an empty string is with length, e.g. if (!length $hash{key}), but make sure to check defined first, because length(undef) will also be false (and before Perl v5.12, will throw a warning).

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Checking for blank string
by Himaja (Novice) on Sep 26, 2016 at 08:46 UTC

    Hi Hauke, The below code works, but still getting the waring mentioned above. Guess I can live with it though. Thanks :)

    $VAR1 = { 'X92' => '', 'AA571' => '0.00', 'AA842' => '0.00', 'B6' => '0', 'E47' => 'SRAM (ssbw)', 'M83' => '', 'B29' => '0' } if(defined $sheet->{$cell} && length($sheet->{$cell}))
        > so the warning must be coming from some other undef value somewhere else in your code

        Maybe the key doesn't exist in the hash at all?

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,