Statement: This magic Perl series for Liu Xing (http://deepfuture.iteye.com/) original, without the author's authorization, no one and institutions can reprint 1. Hash embedded Array
The syntax format is as follows:
Declaration and definition
My % hash variable = (
Hash key 1 => [array element 1, array element 2 ,..., Array Element N],
Hash key 2 => [array element 1, array element 2 ,..., Array Element N],
......
......
Hash key N => [array element 1, array element 2 ,..., Array Element N]
);
Access a single element of an embedded array:
$ Hash variable name {hash key}-> [array subscript]
Access the embedded array:
@ {$ Hash variable name {hash key }}
For example, a game map contains the coordinates of a group of buildings as follows:
Weapons store:
Training venue: 85,196
Equipment stores:
Magic store:, 45
Use a hash embedded array to store and access the data.
1) Storage
My % game = (
"Weapons store" => [123,35],
"Training ground" => [85,196],
"Clothing store" => [],
"Magic store" => []
);
2) Access
Coordinates for accessing the device store:
Printf ("% d, % d", @ {$ game {"defense shop "}});
Coordinate Y value for accessing the magic store:
Print $ game {"device store"}-> [1];
You can use a hard quote to assign values to an embedded array.
My % game;
My @ array = (123,35 );
$ Game {"weapons store" }=\@ array;
My @ array = (85,196 );
$ Game {"training ground" }=\@ array;
My @ array = (67,96 );
$ Game {"clothing store" }=\@ array;
My @ array = (67,96 );
$ Game {"magic store" }=\@ array;
Printf ("% d, % d", @ {$ game {"defense shop "}});