Okay, So without using hashes, here is a sample showing a crude way of getting the sort I need (annotated for clarity):

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @results = (["chpt10_2", "sent. 2", "alice", "nsubj", "animals", "p +rotect"], ["chpt12_1", "sent. 54", "bob", "nsubj", "cells", "prot +ect"], ["chpt25_4", "sent. 47", "carol", "nsubj", "plants", "p +rotect"], ["chpt34_1", "sent. 1", "dave", "nsubj", "cells", "prot +ect"], ["chpt35_1", "sent. 2", "eli", "nsubj", "cells", "prote +ct"], ["chpt38_1", "sent. 1", "fred", "nsubj", "animals", "pr +otect"], ["chpt54_1", "sent. 1", "greg", "nsubj", "uticle", "pro +tect"] ); my @sort_results = sort {lc $a->[4] cmp lc $b->[4]} @results; ##By alp +habet of arg1 my $last_word; my $current_word; my $word_count; $sort_results[-1][6] = 1; ##This weird step is b/c last element didn't + get 7th column appended for my $j (0 .. $#sort_results) { ##[ROW][COLUMN] $current_word = $sort_results[$j][4]; ## current word is arg1 of w +hichever matchset is being looked at (alphabetical) if (lc $last_word eq lc $current_word) { $word_count++; ##If seen before, increment freq. count } else { ##new word if ($j != 0) ##unless it's the first row { for (my $k = 1; $k <= $word_count; $k++) { ##make a new column with freq. Each of the previous see +n word will have to have the same freq. number so iterate back and ma +ke them all the same word count $sort_results[($j-$k)][6] = $word_count; } } ##Now set up for next iteration $last_word = $current_word; $word_count = 1; } } @sort_results = sort {$b->[6] <=> $a->[6]} @sort_results; ##Sort the r +esults by the new 7th freq. column for my $i (0 .. $#sort_results) { print "$sort_results[$i][0], $sort_results[$i][1]: "; ##chptnum, + sent num print "$sort_results[$i][2]\n\n"; ##sentence print "gramatical relation: $sort_results[$i][3]; argument: $sor +t_results[$i][4]; freq: $sort_results[$i][6]\n\n\n"; ##dependency a +rgs }

I would appreciate either a new, better way to do this (I think hashes are the way to get it done), or just an improvement on this crude code. Thanks again for all your help!


In reply to Re: How to (get started on) sort AoA or AoH by frequency by jonc
in thread How to (get started on) sort AoA or AoH by frequency by jonc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.