chomp $readline; my ($key , $value) = (split /::/, $readline); defined $key and $data_ids{$key} = $value;

Which is the same as saying:

chomp $readline; my ($key , $value) = (split /::/, $readline); $data_ids{$key} = $value if $key;

Which is the same as saying:

chomp $readline; if ( my ($key , $value) = (split /::/, $readline) ) { $data_ids{$key} = $value; }

Sorry, but that's wrong. The three code variants have similar, but not identical effects:

The first one stores any defined key (and value) in %data_ids, including the empty string and 0 (zero), but excluding undef. The second one stores only those keys in %data_ids which are true in boolean context. This excludes the empty string, 0, and undef. The third variant stores any key as long as split returns at least one value. This includes the empty string, 0, and undef.

Also, the scope of $key and $value is limited to the if block in the third variant, but not in the first and second variant.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: use of uninitialized value in hash element problem by afoken
in thread use of uninitialized value in hash element problem by mrityunjaynath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.