Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi !

This script should do what you want, specifically my_sort(), the rest is just to get a test environment.
use strict; sub my_sort { my $max_index = $#{@{$a->{Path}}} > $#{@{$b->{Path}}} ? $#{@{$a->{P +ath}}} : $#{@{$b->{Path}}}; for (0..$max_index) { my $r = $a->{Path}->[$_] <=> $b->{Path}->[$_]; return $r if $r; } return 0; } sub print_tree { my $tree = shift; for my $member (@$tree) { print join (' ', @{$member->{Path}})."\n"; } } my $input = <<EOF; 5 32 37 5 32 38 5 32 39 3 12 11 19 20 3 12 11 21 3 12 22 3 12 23 5 32 40 3 12 24 5 32 41 3 25 5 32 42 2 26 5 32 43 2 26 27 2 26 28 2 26 29 0 1 1 2 1 3 3 12 10 1 4 3 12 11 1 5 3 12 2 6 3 12 13 3 12 7 3 12 11 19 14 3 12 8 2 26 30 3 12 11 19 15 3 12 9 5 32 31 3 12 11 19 16 5 32 3 12 11 19 17 5 32 33 3 12 11 19 18 5 32 34 3 12 11 19 5 32 35 5 32 36 EOF # # prepare array of hashes # my @Tree; for (split "\n", $input) { my @a = split (' ', $_); push @Tree, {Path=>\@a}; } print "ORIGINAL:\n"; print_tree(\@Tree); my @Tree_sorted = sort my_sort @Tree; print "SORTED:\n"; print_tree(\@Tree_sorted);
---- kurt

In reply to Re: Complex Sort - using varying numbers of parameters by amphiplex
in thread Complex Sort - using varying numbers of parameters by George_Sherston

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 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? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2021-07-27 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?