Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Sorting comma-delimited records

by vladb (Vicar)
on May 31, 2002 at 17:49 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://170784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found