in reply to Sort array according to a value in each element?
I'm not certain how to approach this problem: split or regex? hash or sort()?I'd add 'databases' to that list of possible solutions although for most circumstances the other answers in this thread are better.
#!perl -w use strict; use DBI; my $aryref = [ ['Item1','2 foo','2 bar'] , ['Item2','0 foo','1 bar'] , ['Item3','1 foo','3 bar'] , ['Item4','1 foo','2 bar'] ]; my $dbh=DBI->connect('dbi:AnyData:'); $dbh->ad_import('tmp','ARRAY',$aryref,{col_names=>'c1,c2,c3'}); printf "%s\n",join ' ',@$_ for @{ $dbh->selectall_arrayref( 'SELECT * FROM tmp ORDER BY c3 DESC, c2 DESC' )}; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Sort array according to a value in each element?
by McMahon (Chaplain) on May 24, 2004 at 19:13 UTC | |
by jZed (Prior) on May 24, 2004 at 21:35 UTC |