Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Sorting comma-delimited records

by vladb (Vicar)
on May 31, 2002 at 17:49 UTC ( #170784=note: print w/replies, xml ) Need Help??


in reply to Sorting colon-delimited records

You can store your records in a hash (just as Beatnik pointed out :) using each record's second field for the key.
use strict; use Data::Dumper; my @a = qw(foo:baz:faz foo:bar:fuss); my %h= map{ (split(/\:/,$_))[1] => $_ } @a; print Dumper(\%h); # to force a '\n' printed after each array element. $,="\n"; print @h{keys %h};
Getting them inside a hash will assure that your records are sorted by the second field in alphabetical order. Here's the output:
$VAR1 = { 'bar' => 'foo:bar:fuss', 'baz' => 'foo:baz:faz' }; foo:bar:fuss foo:baz:faz


_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-04-17 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?