Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You've been pointed to documentation which you appear not to have read. You been asked for information which you haven't supplied. Without doing these things, I don't know how you think we can help you.

I provided a link to sort. Here you'll find many examples including this basic one for sorting numerical data in descending order:

# sort numerically descending @articles = sort {$b <=> $a} @files;

Corion provided a link to DBI (in Re^3: Ranking MySQL Entries?). If you're unfamiliar with that module, look the "Simple Examples" section in that documentation.

Once you have your data, in whatever data structure you choose, you'll probably need a more complicated sort than the basic example shown above. Perhaps something like this:

#!/usr/bin/env perl -l use strict; use warnings; use Data::Dump; my @unordered = ( { id => 12, rownum => 1, rank => 27 }, { id => 31, rownum => 3, rank => 72 }, { id => 45, rownum => 5, rank => 54 }, ); my @ordered = sort { $b->{rank} <=> $a->{rank} } @unordered; print 'Unordered:'; dd \@unordered; print 'Ordered:'; dd \@ordered;

Output:

Unordered: [ { id => 12, rank => 27, rownum => 1 }, { id => 31, rank => 72, rownum => 3 }, { id => 45, rank => 54, rownum => 5 }, ] Ordered: [ { id => 31, rank => 72, rownum => 3 }, { id => 45, rank => 54, rownum => 5 }, { id => 12, rank => 27, rownum => 1 }, ]

You need to follow the guidelines in "How do I post a question effectively?". Note what it says about posting code, data, output and warning/error messages. Pay particular attention to what it says about providing "a minimal script that reproduces your problem" in your post. Unless you do this, we can not help you further!

-- Ken


In reply to Re^3: Ranking MySQL Entries? by kcott
in thread Ranking MySQL Entries? by jdlev

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found