in reply to Re: splitting array values
in thread splitting array values

You seem to be doing a lot of work for something quite simple:
my @ranks = sort { $b <=> $a } keys %rank; for my $r (@ranks) { print "$r $rank{$r}\n"; }
Why join all of the keys together with a space, then split them apart again?

Replies are listed 'Best First'.
Re: Re: Re: splitting array values
by mkurtis (Scribe) on May 23, 2004 at 00:05 UTC
    Thats what I though duff, but your code doesn't sort them, for some reason they stay in the same order and I don't know why.

    Thanks

splitting array values
by mkurtis (Scribe) on Jun 01, 2004 at 02:47 UTC
    Podmaster, Heres whats happening. Ive got a scalar full of number values, some negative. It is stored in $sorted. From there the code goes like this
    foreach my $sorted(@sorted){ $scorehash{$sorted} = undef; } print Dumper(%scorehash); my @ranks2 = sort { $b <=> $a } keys %scorehash; print Dumper(\@ranks2); print $ranks2[0];
    the output is all the values not in order for both printings. Thanks

      I don't know what you are trying to do with that code... also work on your tabs. They kind of confuse the code. Espicially when that forloop is only one line.

      -- Jamie Payne
Re: Re: Re: splitting array values (example)
by mkurtis (Scribe) on Jun 01, 2004 at 03:15 UTC
    Okay, I get these keys from the hash:
    When printed with Data Dumper they look like this:
    $VAR1 = [ '-12' ]; $VAR1 = [ '7' ]; $VAR1 = [ '26' ]; $VAR1 = [ '-123' ]; $VAR1 = [ '7' ]; $VAR1 = [ '39' ]; $VAR1 = [ '30' ]; $VAR1 = [ '32' ]; $VAR1 = [ '-504' ]; $VAR1 = [ '-12' ]; $VAR1 = [ '150' ];
    They are always in that order, even when I sort them, reverse them ...

    I think this is what you want

    Retitled by Chady -- was "Example"