in reply to hash first value

You cannot sort a hash. You can only sort the hash keys. The function for sorting things is called, unimaginatively, sort.

Where exactly do you have problems?

Replies are listed 'Best First'.
Re^2: hash first value
by gfarhat (Novice) on Apr 10, 2008 at 15:13 UTC
    Thats what i meant, sort has keys

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

      • 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.

      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?