in reply to Sorting hashes on non-keys

You want the msg ids sorted in order of their "from" or "to" values, right? If so, here's some example code to sort them based on their associated "from" values.
my @sorted_ids = sort {$mailarray{$a}{"from"} cmp $mailarray{$b}{"from +"}} keys %mailarray;

If your list is large, you may want to make this a bit faster with a Schwartzian Transform.

Two minor things I noticed: I think you'll need to get rid of the ,/ after $to on the fourth line to get your code to run. Also, you're always adding a space to the "to" value even if the "to" value was previously empty. Instead, you may want to check to make sure there is already something there before adding a space separator, maybe like this (although it's kind of ugly and I'm not sure whether you need to worry about the value existing but being undefined, or being defined and empty):

$mailarray{$msgid}{"to"} .= (exists $mailarray{$msgid}{"to"} and length $mailarray{$msgid}{"to +"} ? " " : ""). $to if ($msgid, $to) = ... # your regex here

-- Mike

--
just,my${.02}

Replies are listed 'Best First'.
Re: Re: Sorting hashes on non-keys
by Anonymous Monk on Feb 22, 2003 at 17:56 UTC
    > If your list is large, you may want to make this a bit faster with a Schwartzian Transform. <

    That went WAY over my head! :-)

    >Also, you're always adding a space to the "to" value even if the "to" value was previously empty.<

    Cool! Thanks! I was having problems with "to" being undefined (the compiler was giving me lots of errors). Hopefully this will let me clean up my code.

        > If your list is large, you may want to make this a bit faster with a Schwartzian Transform.

        That went WAY over my head! :-)

      Then one certain way of improving your Perl skills is to read up on it. :-) Figuring out the Schwartzian Transform probably shouldn't be your highest priority at the moment, but it'll help your understanding of sorting, arrays, and the infamous map.

      If you're interested, I strongly recommend japhy's excellent article Re: Helping Beginners (continued).

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me
      The hell with paco, vote for Erudil!