Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Sorting a hash. What am I doing wrong?

by Arien (Pilgrim)
on Jan 14, 2003 at 00:45 UTC ( #226674=note: print w/replies, xml ) Need Help??

in reply to Sorting a hash. What am I doing wrong?

Its name suggests that @uniq should be filled like this:

my @uniq = sort { $a <=> $b } grep { $seen{$_} == 1 } keys %seen;

In other words: get the keys that occur only once and sort them numerically.

— Arien

Replies are listed 'Best First'.
Re: Re: Sorting a hash. What am I doing wrong?
by zakb (Pilgrim) on Jan 14, 2003 at 16:19 UTC

    A hash's keys are always unique.

    #!/usr/bin/perl -w use strict; my %hash = ( key1 => '1', key1 => '2' ); print join("\n", keys %hash);

    prints 'key1' only...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://226674]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-10-06 23:54 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (29 votes). Check out past polls.