Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Retrieve list of indices from ...Prepare binary files for I/O (Berikutnya)
Functions for real %HASHes

Return a list of the values in a hash

Daftar Isi

  • values HASH

  • values ARRAY
  • values EXPR

    In list context, returns a list consisting of all the values of the namedhash. In Perl 5.12 or later only, will also return a list of the values ofan array; prior to that release, attempting to use an array argument willproduce a syntax error. In scalar context, returns the number of values.

    When called on a hash, the values are returned in an apparently randomorder. The actual random order is subject to change in future versions ofPerl, but it is guaranteed to be the same order as either the keys oreach function would produce on the same (unmodified) hash. Since Perl5.8.1 the ordering is different even between different runs of Perl forsecurity reasons (see Algorithmic Complexity Attacks in perlsec).

    As a side effect, calling values() resets the HASH or ARRAY's internaliterator, see each. (In particular, calling values() in void contextresets the iterator with no other overhead. Apart from resetting theiterator, values @array in list context is the same as plain @array.(We recommend that you use void context keys @array for this, butreasoned that taking values @array out would require moredocumentation than leaving it in.)

    Note that the values are not copied, which means modifying them willmodify the contents of the hash:

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

    Starting with Perl 5.14, values can take a scalar EXPR, which must holda reference to an unblessed hash or array. The argument will bedereferenced automatically. This aspect of values is considered highlyexperimental. The exact behaviour may change in a future version of Perl.

    1. for (values $hashref) { ... }
    2. for (values $obj->get_arrayref) { ... }

    To avoid confusing would-be users of your code who are running earlierversions of Perl with mysterious syntax errors, put this sort of thing atthe top of your file to signal that your code will work only on Perls ofa recent vintage:

    1. use 5.012;# so keys/values/each work on arrays
    2. use 5.014;# so keys/values/each work on scalars (experimental)

    See also keys, each, and sort.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Retrieve list of indices from ...Prepare binary files for I/O (Berikutnya)