MonkPaul has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Can anybody please tell me why this prints the hash key and not its value. It originaly worked but now it does not.

print("<TD align=center>$evals{$element}</TD>");
- where $element is the element of an array that holds the same value as the hash key.

Thanks.

Replies are listed 'Best First'.
Re: Hash print problems
by davidrw (Prior) on Jul 23, 2005 at 15:19 UTC
    That should work .. how is %evals set? are you sure you didn't do something that altered the hash contents? What does a use Data::Dumper; print Dumper \%evals; show?
      Ah, i have a problem. The Data::Dumper shows the same value in the hash key and value. I havent changed the assignment though.

      Furter investigation is required.

      Here is the call method:

      %evals = parseFiles::getEvals(); print Dumper \%evals;

      and here is the assignment:

      for(my $i = 0 ; $i<scalar @blastLine; $i++) { if ($blastLine[$i] =~ /^>/) { $counter = 0; $current_subject = $blastLine[$i]; chomp ($current_subject); push (@subjects, $current_subject); $alignment->{$current_subject} = ""; ### assignment here for key value#### $evals{$current_subject} = $blastLine[$i]; } $alignment->{$current_subject} = $alignment->{$current_subject}.$b +lastLine[$i]; if($blastLine[$i] =~ /\bScore/) # check to see if the current line points to the e-value { $counter++; my @tempArray = split(",",$blastLine[$i]); # chop the line into an array for processing $tempArray[1] =~ s/(Expect|Expect\(2\))\s=\s//g; #strip off an +y digits,spaces, or = signs to get just e-value if($counter eq 1) { ### assignment here for value#### $evals{$current_line} = $tempArray[1]; } } }

      this shows:

      $VAR1 = { '>gi|19908487|gb|AF343350.1|' => '>gi|19908487|gb|AF343350.1 +|'
        I'm probably missing your intent here, but I see that you:
        $current_subject = $blastLine[$i];
        and then you:
        $evals{$current_subject} = $blastLine[$i];

        This looks like it would produce a hash with matching key and value.