Perl Programming/Keywords/values

Previous: utime Keywords Next: vec

The values keyword edit

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 edit

  values HASH
  values ARRAY
  values EXPRESSION

Examples edit

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

for (values %hash) {
  print;
}
223311


See also edit

Previous: utime Keywords Next: vec