- 论坛徽章:
- 0
|
此贴只是用于记录一些自己觉得有趣的东西,有兴趣的朋友可以仁者见仁。
=============================================
use 5.01;
use strict;
use warnings;
my @listH = ("foo", 35, "foo2", 35, "bar", 0, 2.5, "hello", "betty", "bye");
say "The list is: @listH";
# One key without value defined in the hash.
# It's same with following:
# my %testHash = ("foo"=> 35, "foo2"=> 35, "bar"=> undef, 2.5=> "hello", "betty"=> "bye");
my %testHash = ("foo"=> 35, "foo2"=> 35, "bar"=> , 2.5=> "hello", "betty"=> "bye",);
my @str = %testHash;
my %testHashRev = reverse %testHash;
my @str1 = %testHashRev;
say "\n\@str is: @str";
say "After reversed the hash: @str1";
Output:
============================================
The list is: foo 35 foo2 35 bar 0 2.5 hello betty bye
Odd number of elements in hash assignment at Y:\PerlT\ex13.pl line 11.
Use of uninitialized value $some_hash{"bye"} in list assignment at Y:\PerlT\ex13.pl line 14.
Use of uninitialized value $str[3] in join or string at Y:\PerlT\ex13.pl line 16.
@str is: bar 2.5 bye hello betty foo 35 foo2 35
After reversed the hash: bye 35 foo betty hello 2.5 bar
[ 本帖最后由 bequan 于 2009-12-23 17:33 编辑 ] |
|