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.