in reply to Uninitialized Value

I'm not getting the warning with the data you provided. Maybe there's an empty line at the end of the input file?

Please, indent the code.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Uninitialized Value
by PilotinControl (Pilgrim) on May 18, 2015 at 16:47 UTC

    That must have been it. I deleted the data.txt file and made a new one and that error did not show up. Now how do I avoid that from happening? Is there a way for the code to ignore the whitespace or any type of null in the data file?

      Just add after 'chomp;':
      next unless length;

        That’s a good way to bypass blank lines, but it won’t bypass a line containing only spaces, or a line containing “word” characters and/or digits but no colons. In both these cases, there is nothing to split on, so $field[1] is undefined. Rather than trying to test the line to predict whether $field[1] will be defined, a simpler and safer approach is to test for the condition causing the warnings directly:

        next unless defined $field[1];

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Is there a way for the code to ignore the whitespace or any type of null in the data file?

      while (<FILE>) { if ($_ =~ /^$/) { print "it's blank\n"; next; #process next line } else { print "it's NOT blank\n"; } }

      if($_ =~ /^$/) can also be written as if(/^$/)


      All is well. I learn by answering your questions...

        if ($_ =~ /^$/)

        This code does not detect whitepace (a line of all spaces, for example) as requested.

        Perhaps this would work better:

        if ($_ =~ /^\s*$/)

        ...also, the next is unnecessary.