Camelia
Prev: Perl 6 Hashes

Hashes (Associative Arrays)

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/env 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>;

Output

examples/hash/create_hash.p6.out
Foo
foo@bar.com
Bar

Prev: Perl 6 Hashes

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: