in reply to Re: hash first value
in thread hash first value

Thats what i meant, sort has keys

The probleme is how to print only the first value in the hash

Replies are listed 'Best First'.
Re^3: hash first value
by Fletch (Bishop) on Apr 10, 2008 at 15:44 UTC
    • Make a sorted list of keys.
    • print using the first of the keys.
    • Make that the last thing you do in your loop.
    • Profit!

    (Or simply use an array slice to pull off my $first_key = (sort keys %foo)[0] and just use that instead of setting up a loop . . .)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^3: hash first value
by aufflick (Deacon) on Apr 11, 2008 at 01:09 UTC
    So you want the first entry of the key/value set in your @array, where each entry in the @array is a comma separated list of key/val?

    my %hash = map { @_ = split /,/, $_; $_[0] => $_[1] } @array; my $first_key = (sort keys %hash)[0];

    You might not want to code it quite so compactly in a real app, but you should get the gist of it - turn into a hash, then take the first key from sorting the keys.

    Is that what you mean?