Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Sorting entries in a DBM hash by one of the variables (http://www.velocityreviews.com/forums/t24769-sorting-entries-in-a-dbm-hash-by-one-of-the-variables.html)

Topher 01-21-2004 01:52 PM

Sorting entries in a DBM hash by one of the variables
 
Hi,

I have a slight problem in that I want to list all the entries in a
DBM file. I'm fine with sorting my the key, but I want to sort by one
of the variables in the value - I know how to do all of it with the
exception of specifying which variable is in the value: if the
key-value pair consists of the ID (the key) and a load of variables
concatenated with , presumably at some point I will need to split
them - but then I don't know where and at which point I will need to
say 'sort by this and not this.' I have searched around and can't
find anything...

Hope this makes sense to someone... Thanks.

Chris

Gunnar Hjalmarsson 01-21-2004 02:28 PM

Re: Sorting entries in a DBM hash by one of the variables
 
Topher wrote:
> I have a slight problem in that I want to list all the entries in a
> DBM file. I'm fine with sorting my the key, but I want to sort by
> one of the variables in the value


This is one example that sorts by the second separated "variable":

my @sortedkeys = sort {
($dbmhash{$a} =~ /([^]*)/)[0]
cmp
($dbmhash{$b} =~ /([^]*)/)[0]
} keys %dbmhash;

It might get you started.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



All times are GMT. The time now is 01:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.