wylie has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to sort on the "Name" field after the following select statement. I'm unsure how I should be manipulating the dereferenced data structure to enable a sort on "Name".
Any ideas what I should be doing?
Wylie# create statement handle my $sth = $dbh->prepare(" SELECT ArchiveID,ArchiveName AS Name, ArchiveBrowseLocation AS Locat +ion FROM tblArchive WHERE ArchiveCategory LIKE '%$searchterm%' ORDER BY '$searchorder'"); #execute SQL search $sth->execute(); #create a reference to the search results $array_ref = $sth->fetchall_arrayref(); #Dereference the data structure returned by the #preceding line. #For each row in the returned array reference foreach my $row(@$array_ref) { my ( $ArchiveID, $Name, $Location ) = @$row; } #Sort statement in here. Something like the following? #@$row = sort { $name1 cmp $name2 } @$row; #output to another script to layout the HTML to follow
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I sort on one of the fields in a dereferenced array reference?
by Fletch (Bishop) on Apr 16, 2002 at 04:05 UTC | |
|
Re: How do I sort on one of the fields in a dereferenced array reference?
by particle (Vicar) on Apr 15, 2002 at 13:59 UTC |