in reply to Re: Sorting or Aligning Parallel Hashes
in thread Sorting or Aligning Parallel Hashes

Thanks very much for the help.
Could you explain further how to use the sorted hash "A" to align the second hash "B"
  • Comment on Re^2: Sorting or Aligning Parallel Hashes

Replies are listed 'Best First'.
Re^3: Sorting or Aligning Parallel Hashes
by ikegami (Patriarch) on Mar 29, 2006 at 17:10 UTC

    There's no such thing as a sorted hash(*), and I don't know what kind of terminology "align" is. You're confusing yourself by trying to be technical. Your data does NOT consist of unsorted hashes, sorted hashes and alignments; your data consists of scores, keywords, line numbers, text and the relationships between them.

    Your question is then "Could you explain further how to get the keywords for a list of (sorted) scores?" I used:

    my @sorted_words = map { $HashA{$_} } @sorted_scores;
    I could also have used:
    my @sorted_words; foreach (@sorted_scores) { push(@sorted_words, $HashA{$_}; }

    %HashA defines the relationship between scores and keywords. To get a list of keywords for a list of scores, simply loop over all the scores and use %HashA to find the corresponding keywords.

    * - Well, it's possible using tie, but that's neither needed nor relevant here.

      I don't get why you didn't use a hash slice.
      my @sorted_words = @HashA{@sorted_scores};

      push(@sorted_words = $HashA{$_};
      That is sooo wrong, I can't believe you wrote that.
      push @sorted_words, $HashA{$_};
        Goind points. The second was a copy and paste error. I fixed it in the original.