Sorting entries in a DBM hash by one of the variables

T

Topher

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
 
G

Gunnar Hjalmarsson

Topher said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top