< Perl Programming < Keywords

The values keyword

values returns a list of all the values of the named HASH, when called in list context. Using Perl 5.12 or later, it will also return a list of the ARRAY. Older versions would produce a syntax error. If called in scalar context, values returns the number of values in the object.

A side effect is that any call on an ARRAY or a HASH will reset the internal iterator of the object. If called in void context resets only the iterator. In list context, values @array is the same as @array.

The values are returned as call-by-reference, so any modification to the elements would change the object content.

From Perl 5.14 onwards, values can evaluate an EXPRESSION that should have the reference to an unblessed hash.

Syntax

  values HASH
  values ARRAY
  values EXPRESSION

Examples

%hash = (foo => 11, bar => 22, baz => 33);

for (values %hash) {
  print;
}
223311

See also

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.