in reply to Can I avoid loops getting the single value from a hash without knowing the key?

> If a hash has only a single value, is there a nice way to get the value without knowing the key and without a foreach loop?

A hash in list context returns just all pairs, so

  (undef, $value) = %hash

will do!

The undef syntax just ignores the key if you really don't need it.

Regarding your code .... Sorry tl;dr, please keep it short next time!

HTH! :)

Cheers Rolf

(addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Can I avoid loops getting the single value from a hash without knowing the key?
by anadem (Scribe) on Jun 12, 2014 at 22:24 UTC
    Ah just what I need, thanks! tl;dr is fine ;-)