Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Sorting

by mfriedman (Monk)
on May 31, 2002 at 17:41 UTC ( #170780=note: print w/replies, xml ) Need Help??

in reply to Sorting colon-delimited records

I would reccomend using an array of arrays and sorting the references to the arrays based on the value of the second element. For the sake of argument, I am going to assume that you have colon-delimited fields, one record per line, and that all the data has been loaded into $data.

#!/usr/bin/perl -w use strict; my $data = get_data_from_somewhere; # First split the data up into a 2D structure my @struct; for (split /\n/, $data) { push @struct, [ split /:/ ] } # Now we sort the struct on the second element of the nested arrays @struct = sort { $a->[1] cmp $b->[1] } @struct;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://170780]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-04-13 11:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found