Perl 5 version 14.2 documentation
- values ARRAY
- values EXPR
Returns a list consisting of all the values of the named hash, or the values of an array. (In 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
eachfunction would produce on the same (unmodified) hash. Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see Algorithmic Complexity Attacks in perlsec).
As a side effect, calling values() resets the HASH or ARRAY's internal iterator; see each. (In particular, calling values() in void context resets the iterator with no other overhead. Apart from resetting the iterator,
values @arrayin list context is the same as plain
@array. We recommend that you use void context
keys @arrayfor this, but reasoned that it taking
values @arrayout would require more documentation than leaving it in.)
Note that the values are not copied, which means modifying them will modify the contents of the hash:
Starting with Perl 5.14,
valuescan take a scalar EXPR, which must hold a reference to an unblessed hash or array. The argument will be dereferenced automatically. This aspect of
valuesis considered highly experimental. The exact behaviour may change in a future version of Perl.