Last time when I had an error of uninitialized value, I was able to fix it by simply initializing the variable.

Don't do that! Or at least, don't do that unless you understand why the variable was uninitialised and providing a default it the correct solution. Just initialising a variable to mask a warning is not fixing the bug in your code.

In a similar way, declaring all your variables up front in a block just to satisfy strict negates the virtue of using strict. In your sample code for example you use $line in a loop, but declare it outside the loop - that's bad. You declare $data then initialise it in the following line. Don't! Declare it where you initialise it.

$gi highlights the problem. It is declared up from with everything else so that strips any meaning that could be inferred from its scope. However the way it is used implies that $gi retains state across iterations of the while loop, but no check is made in the loop to see that $gi has a valid value in the $info{$gi} = $line assignment. An undef check before the assignment and die indicating a badly formatted file may save a lot of grief at some point. BTW, should that assignment perhaps be a push: @$info{$gi}, $line and the array assignments later should then be @temp = @$info{$humangi} and @value = @$info{$gi}?

I notice too that you don't chomp lines in the INFILE2 loop. Is that by design?

True laziness is hard work

In reply to Re: Use of uninitialized value in string eq by GrandFather
in thread Use of uninitialized value in string eq by sophix

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.