Associative Arrays (Hashes)



A hash (also called associative array) is a set of key,value pairs
where the keys are unique strings and the values can have any, err value.

Hashes always start with a % (percentage) sign.
examples/hash/create_hash.p6
#!/usr/bin/perl6
use v6;

my %user_a = "fname", "Foo", "lname", "Bar";

my %user_b = 
    "fname" => "Foo", 
    "lname" => "Bar",
;

say %user_a{"fname"};
%user_a{"email"} = "foo@bar.com";
say %user_a{"email"};

say %user_b<lname>;


Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC
If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed