Perl 值函数



说明

此函数返回 HASH 中包含的所有值的列表。在标量上下文中,返回将返回的值数。它使用与 each 和 keys 函数相同的迭代器,因此顺序也相同。

语法

以下是此函数的简单语法:

values HASH

返回值

此函数在标量上下文中返回哈希表中值的数量,在列表上下文中返回值列表。

示例

以下是显示其基本用法示例代码:

#!/usr/bin/perl -w

%hash = ('One' => 1,
         'Two' => 2,
         'Three' => 3,
         'Four' => 4);

@values = values( %hash );
print("Values are  ", join("-", @values), "\n");

@keys = keys( %hash );
print("Keys are ", join("-", @keys), "\n");

执行以上代码后,会产生以下结果:

Values are  4-3-2-1
Keys are Four-Three-Two-One
perl_function_references.htm
广告
© . All rights reserved.