in reply to Uninitialized value in string eq error but I initialized

The part causing troubles is:
foreach my $id (@ids) { if ($id eq $NSC) { print MY $line; } }
and the uninitialized value is *** $id. ***.
Well. $id comes from @ids. Where does @ids come from?

You declare @ids about 20 ish lines above, and then populate the array with (reformatted, for clarity)

foreach my $row (@ids_table) { my @allcolumns = split /\t/, $row; if($count==0) { $myID= trim($allcolumns[0]); } else { $ids[$count] = trim($allcolumns[0]); } $count++; }

You perform different actions on your input when $count is zero, but you're still adding it to the array with $ids[$count] = ... inside the else block. So, $ids[0] is always going to be undefined.

If you want to add something to the end of an array, use push, not subscripts.

Replies are listed 'Best First'.
Re^2: Uninitialized value in string eq error but I initialized
by Anonymous Monk on Jan 06, 2008 at 00:46 UTC
    That was really the problem. Perl didnt allow me to push into an empty array so I changed the code as follows: $ids[$count-1] = trim($allcolumns[0]) but I will push whenever possible :-). Thanks for help to Funky Monk and all the others.
      Perl didnt allow me to push into an empty array...

      Are you sure?

      my @stuff; push @stuff, 'element'; push @stuff, 'elephant'; local $" = ')('; print "(@stuff)\n";