Hey all, i am writing a report utility, and ended up with a sort question, regarding using sort functions. Im familiar with defining my own sort function or inline, i just cant figure out how to get this sort into a function properly.

I have a hash whose keys are some internal code. They values are hashrefs, each with 2 keys, "dept" and "count". "dept" is a count of how many departments use the code, and count is a total of the people in all those departments. I want everything sorted based on how many departments use each code.
Here's how i do it with an inline sort:
foreach my $code ( sort { $dept_n_code{$a}->{'dept'} <=> $dept_n_code{$b}->{'dept'} } keys %dept_n_code ) { my $desc = $code_map->{$code}; my $out_line = pack $pack_template, $code, $desc, $dept_n_code{$code}->{'dept'}, $dept_n_code{$code}->{'count'}; print REPORT "$out_line\n"; }
Sorry about the odd code formatting, there are rather long lines for this forum.

Anyway, i couldnt figure out a reasonable way to put the sort into its own function, so that i could re-use it. Perhaps the problem is how i have structured the data.
Thanks,
shemp

In reply to Sort function issue by shemp

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.