Sorting entries in a DBM hash by one of the variables

Discussion in 'Perl' started by Topher, Jan 21, 2004.

  1. Topher

    Topher Guest

    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
    Topher, Jan 21, 2004
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jan 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Bruder
    Replies:
    3
    Views:
    951
    spikeysnack
    Aug 3, 2010
  2. rp
    Replies:
    1
    Views:
    496
    red floyd
    Nov 10, 2011
  3. Colvin
    Replies:
    3
    Views:
    163
    Colvin
    Dec 30, 2003
  4. Wes Groleau
    Replies:
    6
    Views:
    129
    Tad McClellan
    Jan 16, 2005
  5. Replies:
    2
    Views:
    132
    Martien verbruggen
    May 17, 2007
Loading...

Share This Page