in reply to Re: Checking for blank string
in thread Checking for blank string

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}))

Replies are listed 'Best First'.
Re^3: Checking for blank string
by haukex (Archbishop) on Sep 26, 2016 at 09:25 UTC
      > 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,

        Hi choroba,

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

        The defined check would still catch that and there wouldn't be a warning. And if $cell was undef, the warning would be "Use of uninitialized value $cell in hash element", not "Use of uninitialized value $data in string eq" as the OP posted here.

        use warnings; use strict; my $sheet = { 'X92' => '', 'AA571' => '0.00', 'AA842' => '0.00', 'B6' => '0', 'E47' => 'SRAM (ssbw)', 'M83' => '', 'X55' => undef, 'B29' => '0' }; sub test { my $cell = shift; if(defined $sheet->{$cell} && length($sheet->{$cell})) { print "Yes\n" } else { print "No\n" } } test(undef); test('A12'); test('X55'); test('M83'); test('B29'); test('E47'); __END__ Use of uninitialized value $cell in hash element at ... No No No No Yes Yes

        Regards,
        -- Hauke D