in reply to Re: use of uninitialized value in string ne
in thread use of uninitialized value in string ne

This snippet was copied an pasted, but it's part of a larger program offcourse.

Also added typical sample input with lots of duplicate lines
  • Comment on Re^2: use of uninitialized value in string ne

Replies are listed 'Best First'.
Re^3: use of uninitialized value in string ne
by Joost (Canon) on Aug 19, 2004 at 10:59 UTC
    open( POCUS, "/home/BioGeek/results_100.out" ||die $!\n";
    has several syntax errors so it can't come from any working code.

    Anyway, it looks to me (if this resembles the actual code, and assuming the warning is from the $results[$i]->[0] eq $disease_name_pocus[0] line) that reading the input file is ok, so probably $disease_name_pocus[0] is undefined. It gets set from @_ which is generally used for passing subroutine arguments. Maybe this is part of a sub and you're calling it incorrectly?

    ofcourse, this code will also warn if you have blank lines or other lines in your input that don't conform to the sample input you gave above.


    $results[$i]->[1] ne $results[ ( $i + 1 ) ]->[1]

    will test one element past the current length of @results at the last iteration, and will also give the warning.

    I'd probably write it something like this:

    my $disease_name_pocus = 'something'; # dont' need array, we only ever use the first value anyway open POCUS,"<","/home/BioGeek/results_100.out" or die "can't open /home/BioGeek/results_100.out: $!\n"; open MARKER, ">","marker_list.txt" or die "Can't open marker_list.txt: $!"; my $lastline; while (<POCUS>) { chomp; # remove newline next unless /\S/; # only use lines that contain something else + than spaces my @result = [split]; next unless $result[0] eq $disease_name_pocus; next if (defined $lastline and $lastline eq $result[1]); $lastline = $result[1]; print MARKER "$result[1]\t$result[4]\n"; } close POCUS; close MARKER;