in reply to Ordering objects using external index

A few examples of the data might have clarified your question. Do you mean something like this?

#! perl -slw use strict; my $uids = [ 9, 1, 4, 7, 2, 0, 3, 6, 8, 5 ]; my $msgs = [ qw[ zero one two three four five six seven eight nine ] ] +; my @msgsByUid = @$msgs[ @$uids ]; print for @msgsByUid; __END__ P:\test>junk nine one four seven two zero three six eight five

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^2: Ordering objects using external index
by kappa (Chaplain) on Sep 06, 2004 at 21:12 UTC
    Aa, kind of. Look:
    my $uids = [ 5674, 1, 4 ]; my $msgs = [ $msg1, $msg4, $msg5674 ];
    Provided $msgNN->uid == NN we'd like to have [ $msg5674, $msg1, $msg4 ].

      That makes it look like your using symbolic references? Ie. Variable names that are (partially) made up from other variable names. eg.

      $uid = 5674; ${'msg' . $uid } = ...;

      In which case, you should be making that a hash directly:

      push @uid, 5674; $msgs{ $uid[ -1 ] } = ...;

      then you wouldn't be having the mapping problem later on. Producing your ordered array would then become a simple hash slice:

      @ordered = @msgs{ @uid };

      It's difficult to know without seeing how the variables and data in your snippets are beiing created.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

        No, of course not, I don't use symbolic references, sorry for confusion.

        I have an array of messages, not a hash. The operation of converting that array to hash keyed by one of message properties (namely, uid) is exactly what I want to avoid as it is expensive.

        I like your suggestion, though, of not having that message array in the first place, but I think this is hard to implement. At present the only format of getting those messages is in unordered lists, too bad (there's IMAP on the other end).