<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

<channel>
<title><![CDATA[Perl 6: Perl 6 Variable Tablet]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet</link>
<description></description>
<pubDate>Tue, 17 Apr 2012 00:54:56 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[Perl 6 Variable Tablet]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet</link>
<description><![CDATA[<div class="wiki">
<p>
<a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_intro_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">Intro<!-- wiki-renamed-link Perl 6 Intro Tablet --></a> - <em>Chapter:</em> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_history_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">0:History<!-- wiki-renamed-link Perl 6 History Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_language_design_tablet" title="(7 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">1:Design<!-- wiki-renamed-link Perl 6 Language Design Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">2:Basics<!-- wiki-renamed-link Perl 6 Basics Tablet --></a> <strong><a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">3:Var<!-- wiki-renamed-link Perl 6 Variable Tablet --></a></strong> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_operator_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">4:Op<!-- wiki-renamed-link Perl 6 Operator Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_io_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">5:IO<!-- wiki-renamed-link Perl 6 IO Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_block_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">6:Block<!-- wiki-renamed-link Perl 6 Block Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_subroutine_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">7:Sub<!-- wiki-renamed-link Perl 6 Subroutine Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_oop_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">8:OOP<!-- wiki-renamed-link Perl 6 OOP Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_regex_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">9:Rx<!-- wiki-renamed-link Perl 6 Regex Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_meta_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">10:Meta<!-- wiki-renamed-link Perl 6 Meta Tablet --></a><br />
<a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_tablets" title="(13 months) These are the Perl 6 Tablets, a comprehensive manual, aimed to support many different ways of learni...">Overview<!-- wiki-renamed-link Perl 6 Tablets --></a> - <em>Appendix:</em> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_index_tablet" title="(13 months)  section Index Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [...">A:Index<!-- wiki-renamed-link Perl 6 Index Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">B:Tables<!-- wiki-renamed-link Perl 6 Lookup Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_cookbook_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">C:Cook<!-- wiki-renamed-link Perl 6 Cookbook Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_delta_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">D:Delta<!-- wiki-renamed-link Perl 6 Delta Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?best_of_perl_6_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">E:Best of<!-- wiki-renamed-link Best Of Perl 6 Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_links_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">F:Links<!-- wiki-renamed-link Perl 6 Links Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_glossary_tablet" title="(13 months)  section Index Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [...">G:Glossary<!-- wiki-renamed-link Perl 6 Glossary Tablet --></a></p>
<hr />
<div class="nlw_phrase"><table class='toc'><tr><td><div class="wiki">
<h3 id="contents">Contents: []</h3>
<ul>
<li><span class="nlw_phrase"><a title="section link" href="#variable_types">Variable Types</a><!-- wiki: {link: [] Variable Types} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#scalar">Scalar</a><!-- wiki: {link: [] Scalar} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#scalar_methods">Scalar Methods</a><!-- wiki: {link: [] Scalar Methods} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#array">Array</a><!-- wiki: {link: [] Array} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#array_slices">Array Slices</a><!-- wiki: {link: [] Array Slices} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#array_methods">Array Methods</a><!-- wiki: {link: [] Array Methods} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#hash">Hash</a><!-- wiki: {link: [] Hash} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#hash_slices">Hash Slices</a><!-- wiki: {link: [] Hash Slices} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#hash_methods">Hash Methods</a><!-- wiki: {link: [] Hash Methods} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#callable">Callable</a><!-- wiki: {link: [] Callable} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#data_types">Data Types</a><!-- wiki: {link: [] Data Types} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#pair">Pair</a><!-- wiki: {link: [] Pair} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#enumeration">Enumeration</a><!-- wiki: {link: [] Enumeration} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#capture">Capture</a><!-- wiki: {link: [] Capture} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#properties_and_traits">Properties and Traits</a><!-- wiki: {link: [] Properties and Traits} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#properties">Properties</a><!-- wiki: {link: [] Properties} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#traits">Traits</a><!-- wiki: {link: [] Traits} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#scoping">Scoping</a><!-- wiki: {link: [] Scoping} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#twigils">Twigils</a><!-- wiki: {link: [] Twigils} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#assignment_and_binding">Assignment and Binding</a><!-- wiki: {link: [] Assignment and Binding} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#assignment">Assignment</a><!-- wiki: {link: [] Assignment} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#binding">Binding</a><!-- wiki: {link: [] Binding} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#special_variables">Special Variables</a><!-- wiki: {link: [] Special Variables} --></span></li>
</ul>
</div>
</td></tr></table><!-- wiki: {toc: } --></div><br /><br /><p>
<em><a target="_blank" title="(external link)" href="http://allisonrandal.com/">Allison Randal<!-- wiki-renamed-hyperlink "Allison Randal"<http://allisonrandal.com/> --></a>: The most basic building blocks of a programming language are its nouns, the chunks of data that get sucked in, pushed around, altered in various ways, and spat out to some new location.</em></p>
<h1 id="variable_types">Variable Types</h1>
<p>
Perl 6 (as Perl 5) knows 3 basic types of variables: <span class="nlw_phrase"><a title="section link" href="#scalar">Scalars</a><!-- wiki: "Scalars"{link: Scalar} --></span> (single values), <span class="nlw_phrase"><a title="section link" href="#array">Arrays</a><!-- wiki: "Arrays"{link: Array} --></span> (ordered and indexed lists of several values) and <span class="nlw_phrase"><a title="section link" href="#hash">Hashes</a><!-- wiki: "Hashes"{link: Hash} --></span> (2 column table, with ID and associated value pairs). They can be easily distinguished, because in front of their name is a special character called <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#sigils">sigil</a><!-- wiki: "sigil"{link: [Perl 6 Lookup Tablet] Sigils} --></span> (latin for sign). Its the $ (similar to S) for Scalars, @ (like an a) for Arrays and a % (kv pair icon) for a Hash. They are now invariant (not changing), which means for instance, an array vaiable starts always with an @, even if you just want a slice of the content.</p>
<blockquote>
$scalar<br />
@array<br />
@array[1] ####### $array[1] in Perl 5<br />
@array[1,2]###### @array[1,2] in Perl 5<br />
%hash<br />
%hash{'ba'} ######### $hash{'ba'} in Perl 5<br />
%hash{'ba','da','bim'} ### @hash{'ba','da','bim'} in Perl 5</blockquote>
<br /><p>
The sigils mark also distinct namespaces, meaning: in one <span class="nlw_phrase"><a title="section link" href="#scoping">lexical scope</a><!-- wiki: "lexical scope"{link: Scoping} --></span> you can have 3 different variables named $stuff, @stuff and %stuff. These sigils <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#contextualizers">can also be used as an operator</a><!-- wiki: "can also be used as an operator"{link: [perl 6 lookup tablet] Contextualizers} --></span> to enforce a context in which the following data will be seen.</p>
<p>
The fourth namespace where you can store and retrieve something under specified names is the one of <span class="nlw_phrase"><a title="section link" href="#callable">subroutines and alike</a><!-- wiki: "subroutines and alike"{link: Callable} --></span>, even if you don't might think of them as variables. It's sigil &amp; has to be used only rarely.</p>
<p>
Special namespaces of Perl 5 (often marked with special syntax) like tokens (__PACKAGE__), formats, file or dir handle and builtins are now regular (mostly scalar) variables or routines.</p>
<p>
Because variables are (as anything in Perl 6) <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_oop_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">objects<!-- wiki-renamed-link Perl 6 OOP Tablet --></a>, they have methods. In fact, <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_operator_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">any operator<!-- wiki-renamed-link Perl 6 Operator Tablet --></a>, including these square or curly brackets you get specific array and hash values with, are just methods of a variable object with a fancy name.</p>
<p>
The primary sigil can be followed by a secondary sigil, called <span class="nlw_phrase"><a title="section link" href="#twigils">twigil, which mostly indicate special scope</a><!-- wiki: "twigil, which mostly indicate special scope"{link: Twigils } --></span> of that variable.</p>
<h2 id="scalar">Scalar</h2>
<p>
This type is known as a storage room for one value, but it's more like a reference that can point to anything: to values of any data type, to <em>code</em>, to <em>objects</em> or to a compound of values like a <span class="nlw_phrase"><a title="section link" href="#pair">pair</a><!-- wiki: "pair"{link: Pair} --></span>, <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_operator_tablet#junctions">junction</a><!-- wiki: "junction"{link: [perl 6 operator tablet] junctions} --></span>, <span class="nlw_phrase"><a title="section link" href="#array">array</a><!-- wiki: "array"{link: Array} --></span>, <span class="nlw_phrase"><a title="section link" href="#hash">hash</a><!-- wiki: "hash"{link: Hash} --></span> or <span class="nlw_phrase"><a title="section link" href="#capture">capture</a><!-- wiki: "capture"{link: Capture} --></span>. The scalar context is now called item context hence the <em>scalar</em> instruction from Perl 5 was renamed to <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#contextualizers">item</a><!-- wiki: "item"{link: [perl 6 lookup tablet] Contextualizers} --></span>.</p>
<blockquote>
$CHAPTER = 3; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#single_line">first comment!</a><!-- wiki: "first comment!"{link: [Perl 6 Basics Tablet]Single Line} --></span><br />
$bin = 0b11; # same value in <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#radix_prefixes">binary format</a><!-- wiki: "binary format"{link: [Perl 6 Basics Tablet]Radix Prefixes} --></span><br />
$pi = 3.14159_26535_89793; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#number_literals">the underscores just ease reading</a><!-- wiki: "the underscores just ease reading"{link: [Perl 6 Basics Tablet]Number Literals} --></span><br />
$float = 6.02e-23; # floating number in <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#scientific_notation">scientific notation</a><!-- wiki: "scientific notation"{link: [Perl 6 Basics Tablet]scientific notation} --></span><br />
$text = 'Welcome all!'; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#single_quotes">single quoted string</a><!-- wiki: "single quoted string"{link: [perl 6 Basics tablet] Single Quotes} --></span><br />
$text = <span class="nlw_phrase">&quot;<!-- wiki: {{&quot;}} --></span> What is $pi?<span class="nlw_phrase">&quot;<!-- wiki: {{&quot;}} --></span>; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#double_quotes">double quoted string</a><!-- wiki: "double quoted string"{link: [perl 6 Basics tablet] Double Quotes} --></span>, does eval $pi to its content<br />
$text = q:to'EOT'; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet#heredocs">heredoc string</a><!-- wiki: "heredoc string"{link: [perl 6 Basics tablet] Heredocs} --></span>
<blockquote>
handy for multiline text<br />
like HTML templates or email</blockquote>
EOT<br />
$handle = open $file_name; # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_io_tablet#files">file handle</a><!-- wiki: "file handle"{link: [perl 6 IO tablet] Files} --></span><br />
$object = Class::Name.new(); # an object from a <span class="nlw_phrase"><a title="inter-workspace link: perl6" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_oop_tablet">class</a><!-- wiki: "class"{link: [Perl 6 OOP Tablet] } --></span> with a nested namespace<br />
$condition = 3|5|7; # a <span class="nlw_phrase"><a title="section link" href="#junction">junction</a><!-- wiki: "junction"{link: junction} --></span>, a logical conjunction of values<br />
$arrayref = <span class="nlw_phrase">[0,1,1,2,3,5,8,13,21];<!-- wiki: {{[0,1,1,2,3,5,8,13,21];}} --></span> # a reference to a <span class="nlw_phrase"><a title="section link" href="#array">list of values</a><!-- wiki: "list of values"{link: Array} --></span><br />
$hashref = {'audreyt'=&gt;'pugs', 'pm'=&gt;'pct', 'damian'=&gt;'larrys evil henchman'}; # reference to a <span class="nlw_phrase"><a title="section link" href="#hash">hash</a><!-- wiki: "hash"{link: Hash} --></span><br />
$coderef = sub { do_something_completely_diffenent(@_) }; # pointing to a <span class="nlw_phrase"><a title="section link" href="#callable">callable</a><!-- wiki: "callable"{link: Callable} --></span></blockquote>
<br /><p>
Unlike Perl 5, references are automatically dereferenced to a fitting context. So you could use these $arrayref and $hashref in same way as an array or hash, making $ the universal variable highlighter or prefix, pretty much like in PHP.</p>
<h3 id="scalar_methods">Scalar Methods</h3>
<blockquote>
my $chapter = 3;<br />
undefine $chapter;<br />
defined $a; # false, returns 0</blockquote>
<br /><h2 id="array">Array</h2>
<p>
is an ordered and indexed list of <span class="nlw_phrase"><a title="section link" href="#scalar">scalar variables</a><!-- wiki: "scalar variables"{link: Scalar} --></span>. If not specified otherwise, they can be changed, prolonged and shorten anytime and used as a list, stack, queue and much more. As in Haskell, lists are processed lazily, which means: the compiler looks only at the part he currently needs. This way Perl 6 can handle infinite lists or do computation on lists that are still building up. The <em>lazy</em> command enforces and the <em>eager</em> command prevents that behaviour on any expression.</p>
<p>
The list context is forced with a <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#contextualizers">@ operator or _list()_ command</a><!-- wiki: "@ operator or _list()_ command"{link: [perl 6 lookup tablet] Contextualizers} --></span>. That's not autoflattening like in Perl 5 (automatically convert a List of Lists into one List). If you still want that, <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#contextualizers">say flat(). Or say lol()</a><!-- wiki: "say flat(). Or say lol()"{link: [perl 6 lookup tablet] Contextualizers} --></span> to explicitly prevent autoflattening.</p>
<pre>
@primes = (2,3,5,7,11,13,17,19,23); # an array gets filled like in Perl 5
@primes =  2,3,5,7,11,13,17,19,23 ; # same thing, since unlike P5 round braces just do group
@primes = &lt;2 3 5 7 11 13 17 19 23&gt;; # dito, &lt;&gt; is the new qw()
$arrayref = 2,3,5,7,11,13,17,19,23; # in scalar context you get automatically a reference
$arrayref = item @primes;           # same thing, more explicit
$arrayref = 13,;                    # comma is the new array generator
@primes = 2;                        # array with one element
@primes = [2,3,5,7,11,13,17,19,23]; # array with one element (arrayref)
@dev    = {'dan' =&gt; 'parrot'};      # array with one element (hashref)
@data   = [1..5],[6..10],[11..15];  # Array of Arrays (AoA)
@list   = lol @data;                # no change
@list   = flat @data;               # returns 1..15
</pre>
<br /><h3 id="array_slices">Array Slices</h3>
<pre>
@primes                       # all values as list
@primes.values                # same thing   
@primes.keys                  # list of all indices
&quot;@primes[]&quot;                   # insert all values in a string, uses [] as distinction from mail adresses
$prime = @primes[0];          # get the first prime
$prime = @primes[*-1];        # get the last one
@some = @primes[2..5];        # get several
$cell = @data[1][2];          # get 8, third value of second value (list)
$cell = @data[1;2];           # same thing, shorten syntax
@numbers = @data[1];          # get a copy of the second subarray (6..10)
@copy = @data;                # copy the whole AoA, no more reference passing, use binding instead
</pre>
<br /><h3 id="array_methods">Array Methods</h3>
<p>
Some of the more important things you can do with lists. All the methods can also used like ops in &quot;elems @rray;&quot;</p>
<pre>
? @rray;              # boolean context, Bool::True if array has any value in it, even if its a 0
+ @rray;              # numeric context, number of elements (like in Perl 5 scalar @a)
~ @rray;              # string context, you get content of all cells, stringified and joined, same as &quot;@primes[]&quot;

@rray.elems;          # same as + @rray
@rray.end;            # number of the last element, equal to @rray.elems-1
@rray.cat;            # same ~ @rray
@rray.join('');       # also same result, you can put another string as parameter that gets between all values
@rray.unshift;        # prepend one value to the array
@rray.shift;          # remove the first value and return it
@rray.push;           # add one value on the end
@rray.pop;            # remove one value from the end and return it
@rray.splice($pos,$n);# remove on $pos $n values and replace them with values that follow that two parameter
@rray.delete(@ind);   # delete all cell with indecies of @ind
@rray.exists(@ind);   # Bool::True if all indecies of @ind have a value (can be 0 or '')
@rray.pick([$n]);     # return $n (default is 1) randomly selected values, without duplication
@rray.roll([$n]);     # return $n (default is 1) randomly selected values, duplication possible (like roll dice)
@rray.reverse;        # all elements in reversed order
@rray.rotate($n);     # returns a list where $n times first item is taken to last position if $n is positive, if negative the other way around
@rray.sort($coderef); # returns a sorted list by a userdefined criteria, default is alphanumerical sorting
@rray.min;            # numerical smallest value of that array
@rray.max;            # numerical largest value of that array
$a,$b= @rray.minmax;  # both at once, like in .sort . min or .max a sorting algorith can be provided

@rray.map($coderef);  # high oder map function, runs $coderef with every value as $_ and returns the list or results
@rray.classify($cr);  # kind of map, but creates a hash, where keys are the results of $cr and values are from @rray
@rray.categorize($cr);# kind of classify, but closure can have no (Nil) or several results, so a key can have a list of values
@rray.grep({$_&gt;1});   # high order grep, returns only these elements that pass a condition ($cr returns something positive)
@rray.first($coder);  # kind of grep, return just the first matching value
@rray.zip;            # join arrays by picking first element left successively from here and then there
</pre>
<br /><p>
There is even a whole class of metaoperators that work upon lists.</p>
<h2 id="hash">Hash</h2>
<p>
is in Perl 6 an unordered list of Pairs. <span class="nlw_phrase"><a title="section link" href="#pair">A Pair</a><!-- wiki: "A Pair"{link: Pair} --></span> is a single key =&gt; value association and <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_language_design_tablet#maximum_reusage">appears in many places</a><!-- wiki: "appears in many places"{link: [Perl 6 Language Design Tablet] Maximum reusage} --></span> of the language syntax.</p>
<pre>
%dev =  'pugs'=&gt;'audreyt', 'pct'=&gt;'pm', &quot;STD&quot;=&gt;'larry';
%dev = :rakudo('jnthn'), :testsuite('moritz');            # adverb (pair) syntax works as well
%dev = ('audreyt', 'pugs', 'pm', 'pct', 'larry', &quot;STD&quot;);  # lists get autoconverted in hash context
%compiler = Parrot =&gt; {Rakudo =&gt; 'jnthn'}, SMOP =&gt; {Mildew =&gt; 'ruoso'};       # hash of hashes (HoH)
</pre>
<br /><h3 id="hash_slices">Hash Slices</h3>
<pre>
$value = %dev{'key'};      # just give me the value related to that key, like in P5
$value = %dev&lt;pm&gt;;         # &lt;&gt; autoquotes like qw() in P5
$value = %dev&lt;&lt;$name&gt;&gt;;    # same thing, just with eval
@values = %dev{'key1', 'key2'};
@values = %dev&lt;key1 key2&gt;;
@values = %dev&lt;&lt;key1 key2 $key3&gt;&gt;;
%compiler&lt;Parrot&gt;&lt;Rakudo&gt;; # value in a HoH, returns 'jnthn'
%compiler&lt;SMOP&gt;;           # returns the Pair: Mildew =&gt; 'ruoso'

%dev   {'audrey'};         # error, spaces between varname and braces (postcircumfix operator) are no longer allowed
%dev\  {'allison'};        # works, quote the space
%dev   .&lt;dukeleto&gt;;        # error
%dev\ .{'patrick'};        # works too, &quot;long dot style&quot;, because its its an object in truth 
</pre>
<br /><h3 id="hash_methods">Hash Methods</h3>
<pre>
 ? %dev                    # bool context, true if hash has any pairs
 + %dev                    # numeric context, returns number of pairs(keys)
 ~ %dev                    # string context, nicely formatted 2 column table using \t and \n

$table = %dev;             # same as ~ %dev
%dev.say;                  # stringified, but only $key and $value are separated by \t
@pairs = %dev;             # list of all containing pairs
%dev.pairs                 # same thing in all context
%dev.elems                 # same as + %dev or + %dev.pairs
%dev.keys                  # returns the list with all keys
%dev.values                # list of all values
%dev.kv                    # flat list with key1, value1, key 2 ...
%dev.invert                # reverse all key =&gt; value relations
%dev.push (@pairs)         # inserts a list of pairs, if a key is already present in %dev, both values gets added to an array
</pre>
<br /><h2 id="callable">Callable</h2>
<p>
Internally <span class="nlw_phrase"><a title="inter-workspace link: perl6" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_subroutine_tablet">subroutines</a><!-- wiki: "subroutines"{link: [Perl 6 Subroutine Tablet]} --></span>, <span class="nlw_phrase"><a title="inter-workspace link: perl6" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_oop_tablet">methods</a><!-- wiki: "methods"{link: [Perl 6 OOP Tablet]} --></span> and <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#routine_types">alike</a><!-- wiki: "alike"{link: [Perl 6 Lookup tablet] Routine Types} --></span> are variables with the sigil <em>&amp;</em> and stored in a fourth namespace. They are no more builtins with an own namespace, that can't be overwritten or augmented with your programming. Of course <span class="nlw_phrase"><a title="section link" href="#scalar">scalars</a><!-- wiki: "scalars"{link: Scalar} --></span> can also point to routines.</p>
<pre>
&amp;function = sub { ... };         # store subroutine in callable namespace
function();                      # call/run it

$coderef = sub { ... };          # store it in a scalar
$coderef($several, $parameter);  # run that code
</pre>
<br /><h1 id="data_types">Data Types</h1>
<p>
In contrast to <span class="nlw_phrase"><a title="section link" href="#variable_types">variable types</a><!-- wiki: "variable types"{link: Variable Types} --></span> (container types) every <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#value_types">value has a type</a><!-- wiki: "value has a type"{link: [Perl 6 Lookup tablet] value types} --></span> too. These are also organized internally as classes or roles and can be categorized into 3 piles: the undefined, immutable and the mutable types.</p>
<p>
You can explicitly assign one of these types to you scalar, array or hash variable.</p>
<blockquote>
my Int $a;<br />
my Array of Int @a;</blockquote>
<br /><h2 id="pair">Pair</h2>
<p>
are very new and their syntax is used nearly everywhere in the language, where you have associations between a name and a value.</p>
<pre>
$pair = 'jakub' =&gt; 'helena';  # &quot;=&gt;&quot; is the pair constructor
$pair = :jakub('helena');     # same in adverbial notation
$pair = :jakub&lt;helena&gt;;       # same using &lt;&gt;, the new qw()
$pair.key                     # returns 'jakub'
$pair.value                   # returns 'helena'
$pair.isa(Pair)               # Bool::True
</pre>
<br /><h2 id="enumeration">Enumeration</h2>
<pre>
enum
</pre>
<br /><h2 id="capture">Capture</h2>
<p>
also a new type, that can hold all or a part of the parameters a routine gets. Because Perl knows now positional as well as named parameters, it es some mixture of a list and array.</p>
<pre>
$cap = \(@a,$s,%h);           # creating a capture, &quot;\&quot; was free since there are no references anymore
| $cap                        # flatten into argument list (hash like context)
|| $cap                       # flatten into semicolon list (array like context)
</pre>
<br /><p>
One important difference between a compound structure of lists and hashes and a capture: while <span class="nlw_phrase"><a title="section link" href="#assignment">assignments</a><!-- wiki: "assignments"{link: Assignment} --></span> with = the complete content of the named variables will be copied. But not so in the case of a capture. When I change $s in the last example, the content of $cap changes too, because when parameters to a routine are variables, they are also interpolated in the moment the routine is called, not when its defined.</p>
<h1 id="properties_and_traits">Properties and Traits</h1>
<h2 id="properties">Properties</h2>
<h2 id="traits">Traits</h2>
<h1 id="scoping">Scoping</h1>
<p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#scope_declarator">scope declarator</a><!-- wiki: "scope declarator"{link: [perl 6 lookup tablet] scope declarator} --></span>, <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#scopes">scopes</a><!-- wiki: "scopes"{link: [perl 6 lookup tablet] scopes } --></span></p>
<blockquote>
my $var;<br />
state<br />
temp<br />
let<br />
our $var;<br />
$*var;</blockquote>
<br /><h2 id="twigils">Twigils</h2>
<h1 id="assignment_and_binding">Assignment and Binding</h1>
<h2 id="assignment">Assignment</h2>
<p>
As rightfully expected, assignments are done with the equal sign. But unlike Perl 5 you always get a copy of the right side data assigned to the left, no matter how nested the data structure was (lists of lists eg). You never get in Perl 6 a reference with =. As the only exception may be seen <span class="nlw_phrase"><a title="section link" href="#capture">captures</a><!-- wiki: "captures"{link: capture} --></span>.</p>
<blockquote>
my @original = <span class="nlw_phrase">[1,2],[3,4];<!-- wiki: {{[1,2],[3,4];}} --></span><br />
my $copy = @original[0]; # $copy points to <span class="nlw_phrase">[1,2]<!-- wiki: {{[1,2]}} --></span><br />
<span class="nlw_phrase">@original[0][0]<!-- wiki: {{@original[0][0]}} --></span> = 'fresh stuff'; # <span class="nlw_phrase">$copy[0] holds still 1<!-- wiki: {{$copy[0] holds still 1}} --></span></blockquote>
<br /><h2 id="binding">Binding</h2>
<p>
Since Perl 6 doesn't know of any references, programmer have to use binding to get 2 variables that point to the same memory location.</p>
<pre>
$original = 5;
$original := $mirror;       # normal binding, done on runtime
$original ::= $mirror;      # same thing, but done during compile time
$original = 3;
say $mirror;                # prints 3
$original =:= $mirror       # true, because their bound together
$original === $mirror       # alsotrue, because content and type are equal
</pre>
<br /><h1 id="special_variables">Special Variables</h1>
<p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#special_variables">are listed their table</a><!-- wiki: "are listed their table"{link: [Perl 6 Lookup Tablet] special variables} --></span>. To understand their secondary sigil <span class="nlw_phrase"><a title="section link" href="#twigils">go to the twigil chapter of this tablet</a><!-- wiki: "go to the twigil chapter of this tablet"{link: Twigils} --></span>.</p>
<hr />
<p>
<a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_intro_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">Intro<!-- wiki-renamed-link Perl 6 Intro Tablet --></a> - <em>Chapter:</em> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_history_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">0:History<!-- wiki-renamed-link Perl 6 History Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_language_design_tablet" title="(7 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">1:Design<!-- wiki-renamed-link Perl 6 Language Design Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">2:Basics<!-- wiki-renamed-link Perl 6 Basics Tablet --></a> <strong><a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">3:Var<!-- wiki-renamed-link Perl 6 Variable Tablet --></a></strong> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_operator_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">4:Op<!-- wiki-renamed-link Perl 6 Operator Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_io_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">5:IO<!-- wiki-renamed-link Perl 6 IO Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_block_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">6:Block<!-- wiki-renamed-link Perl 6 Block Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_subroutine_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">7:Sub<!-- wiki-renamed-link Perl 6 Subroutine Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_oop_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">8:OOP<!-- wiki-renamed-link Perl 6 OOP Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_regex_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">9:Rx<!-- wiki-renamed-link Perl 6 Regex Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_meta_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">10:Meta<!-- wiki-renamed-link Perl 6 Meta Tablet --></a><br />
<a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_tablets" title="(13 months) These are the Perl 6 Tablets, a comprehensive manual, aimed to support many different ways of learni...">Overview<!-- wiki-renamed-link Perl 6 Tablets --></a> - <em>Appendix:</em> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_index_tablet" title="(13 months)  section Index Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [...">A:Index<!-- wiki-renamed-link Perl 6 Index Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">B:Tables<!-- wiki-renamed-link Perl 6 Lookup Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_cookbook_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">C:Cook<!-- wiki-renamed-link Perl 6 Cookbook Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_delta_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">D:Delta<!-- wiki-renamed-link Perl 6 Delta Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?best_of_perl_6_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">E:Best of<!-- wiki-renamed-link Best Of Perl 6 Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_links_tablet" title="(13 months)  Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [Perl 6 Languag...">F:Links<!-- wiki-renamed-link Perl 6 Links Tablet --></a> <a href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_glossary_tablet" title="(13 months)  section Index Intro [Perl 6 Intro Tablet] - _Chapter _ 0 History [Perl 6 History Tablet] 1 Design [...">G:Glossary<!-- wiki-renamed-link Perl 6 Glossary Tablet --></a></p>
<hr />
</div>
]]></description>
<author>Herbert Breunung</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet</guid>
<pubDate>Tue, 17 Apr 2012 00:54:56 -0000</pubDate>
</item>

</channel>
</rss>