in reply to Re: Uninitialized Value
in thread Uninitialized Value

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?

Replies are listed 'Best First'.
Re^3: Uninitialized Value
by pme (Monsignor) on May 18, 2015 at 16:53 UTC
    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,

        I've added that code as well...thanks!

Re^3: Uninitialized Value
by vinoth.ree (Monsignor) on May 18, 2015 at 17:30 UTC

    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.