- publishing free software manuals
Perl Language Reference Manual
by Larry Wall and others
Paperback (6"x9"), 724 pages
ISBN 9781906966027
RRP £29.95 ($39.95)

Sales of this book support The Perl Foundation! Get a printed copy>>>

values HASH

values ARRAY

Returns a list consisting of all the values of the named hash, or the values of an array. (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. Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see 22.2.9).

As a side effect, calling values() resets the HASH or ARRAY's internal iterator, see . (In particular, calling values() in void context resets the iterator with no other overhead. Apart from resetting the iterator, values @array in list context is the same as plain @array. We recommend that you use void context keys @array for this, but reasoned that it taking values @array out 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:

for (values %hash)      { s/foo/bar/g }   # modifies %hash values
for (@hash{keys %hash}) { s/foo/bar/g }   # same

See also keys, each, and sort.

ISBN 9781906966027Perl Language Reference ManualSee the print edition