Monday, 14 January 2013

Perl Notes - Hash Arrays


Hash Arrays

Like a hash table – %dict
Use { } to access by key
Assign
$dict{"a"} = "aaa";
$dict{"b"} = "bbb";
Lookup
$dict{"a"} ## lookup value for key "a"
$dict{"b"}
defined($dict{"z"}) ==> false, since no value for "z"
Array Conversion
A hash can be converted to an array of even length with keys in random order
@a = %dict;
Now, @a is ("b", "bbb", "a", "bbb")
%ENV
Special global hash array, contains the environment vars of our runtime

No comments:

Post a Comment