in reply to Re: What is sprintf doing?
in thread What is sprintf doing?

OK, so I *think* what I needed to do was cull all of the unwanted data before sorting. This works, gives no errors, and is substantially faster than what I was doing before. The double regex looks wrong, though>:

my @wanted; foreach $msg(@msgs) { if ($msg =~ m[,\s+(\d+)]) { push @wanted, $msg; } } my @sorted = map{ substr $_, 5; } sort { $b cmp $a } map{ sprintf '%05d%s', $_ =~ m[,\s+(\d+)], $_; } @wanted;

Replies are listed 'Best First'.
Re: Re: Re: What is sprintf doing?
by BrowserUk (Patriarch) on May 25, 2004 at 18:28 UTC

    Sorry, but I do not understand what you are doing here at all.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
      My source data array is actually more like:

      Item1 - 2 foo, 2 bar argle bargle Item2 - 0 foo, 1 bar floogle Item3 - 1 foo, 3 bar Item4 - 1 foo, 2 bar choogle


      I used the regex in the foreach to remove everything that causes the "uninitialized" and "isn't numeric" messages.

      But I still seem to need the regex in the sprintf statement, to make the sort come out right.