You are viewing the version of this documentation from Perl 5.005_03. View the latest version
values HASH

Returns a list consisting of all the values of the named hash. (In a scalar context, returns the number of values.) The values are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the keys() or each() function would produce on the same (unmodified) hash.

Note that you cannot modify the values of a hash this way, because the returned list is just a copy. You need to use a hash slice for that, since it's lvaluable in a way that values() is not.

for (values %hash)      { s/foo/bar/g }   # FAILS!
for (@hash{keys %hash}) { s/foo/bar/g }   # ok

As a side effect, calling values() resets the HASH's internal iterator. See also keys(), each(), and sort().