📜  珀尔 |键()函数

📅  最后修改于: 2022-05-13 01:54:30.349000             🧑  作者: Mango

珀尔 |键()函数

Perl 中的 keys()函数将 HASH 的所有键作为列表返回。 List 中元素的顺序不必总是相同,但它与 values 和每个函数返回的顺序相匹配。

示例 1:

#!/usr/bin/perl
  
%hash = ('Ten' => 10,
         'Eleven' => 11,
         'Twelve' => 12,
         'Thirteen' => 13);
  
@values = values( %hash );
print("Values are  ", join("-", @values), "\n");
  
@keys = keys( %hash );
print("Keys are ", join("-", @keys), "\n");

输出:

Values are  11-12-13-10
Keys are Eleven-Twelve-Thirteen-Ten

示例 2:

#!/usr/bin/perl
  
%hash = ('Geek' => 1,
         'For' => 2,
         'Geeks' => 3);
  
@values = values( %hash );
print("Values are  ", join("-", @values), "\n");
  
@keys = keys( %hash );
print("Keys are ", join("-", @keys), "\n");

输出:

Values are  3-2-1
Keys are Geeks-For-Geek