<?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 Basics Tablet]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_tablet</link>
<description></description>
<pubDate>Tue, 17 Apr 2012 00:54:12 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[Perl 6 Basics Tablet]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?perl_6_basics_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> <strong><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> <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="#defaults">Defaults</a><!-- wiki: {link: [] Defaults} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#statements">Statements</a><!-- wiki: {link: [] Statements} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#spaces_and_indentation">Spaces and Indentation</a><!-- wiki: {link: [] Spaces and Indentation} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#comments">Comments</a><!-- wiki: {link: [] Comments} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#single_line">Single Line</a><!-- wiki: {link: [] Single Line} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#multi_line">Multi Line</a><!-- wiki: {link: [] Multi Line} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#pod">POD</a><!-- wiki: {link: [] POD} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#quoting">Quoting</a><!-- wiki: {link: [] Quoting} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#delimiter">Delimiter</a><!-- wiki: {link: [] Delimiter} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#interpolation">Interpolation</a><!-- wiki: {link: [] Interpolation} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#single_quotes">Single Quotes</a><!-- wiki: {link: [] Single Quotes} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#double_quotes">Double Quotes</a><!-- wiki: {link: [] Double Quotes} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#quote_words">Quote Words</a><!-- wiki: {link: [] Quote Words} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#heredocs">Heredocs</a><!-- wiki: {link: [] Heredocs} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#paths">Paths</a><!-- wiki: {link: [] Paths} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#regex">Regex</a><!-- wiki: {link: [] Regex} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#code">Code</a><!-- wiki: {link: [] Code} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#number_literals">Number Literals</a><!-- wiki: {link: [] Number Literals} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#radix_prefixes">Radix Prefixes</a><!-- wiki: {link: [] Radix Prefixes} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#general_radix_form">General Radix Form</a><!-- wiki: {link: [] General Radix Form} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#scientific_notation">Scientific Notation</a><!-- wiki: {link: [] Scientific Notation} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#rational_number">Rational Number</a><!-- wiki: {link: [] Rational Number} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#complex_number">Complex Number</a><!-- wiki: {link: [] Complex Number} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#version_number">Version Number</a><!-- wiki: {link: [] Version Number} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="#formatting">Formatting</a><!-- wiki: {link: [] Formatting} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="#perl">perl</a><!-- wiki: {link: [] perl} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#pretty">pretty</a><!-- wiki: {link: [] pretty} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#fmt">fmt</a><!-- wiki: {link: [] fmt} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#sprintf">sprintf</a><!-- wiki: {link: [] sprintf} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#pack">pack</a><!-- wiki: {link: [] pack} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#formats">Formats</a><!-- wiki: {link: [] Formats} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#date_and_time">Date and Time</a><!-- wiki: {link: [] Date and Time} --></span></li>
</ul></ul>
</div>
</td></tr></table><!-- wiki: {toc: } --></div><br /><br /><p>
<em>1st law of language redesign: Everyone wants the colon for their particular syntax.</em> <br />
<em>2nd law of language redesign: Larry gets the colon for whatever he wants.</em></p>
<p>
Basics doesn't mean here not always easy but fundamental.</p>
<h1 id="defaults">Defaults</h1>
<p>
Please start your Perl 6 program with one of the following lines.</p>
<blockquote>
#!/usr/bin/perl6<br />
use v6.0;<br />
v6;</blockquote>
<br /><p>
or just start with a keyword like <strong>module</strong> or <strong>class</strong>. That marks your code as Perl 6 (in case the interpreter defaults to Perl 5) and makes it possible to mix Perl 5 and 6 in one source file.</p>
<p>
To even that little obstacle, you can leave out the usual <em>use strict;</em> and <em>use warnings;</em> in front of every script, because thats now default. Also <em>use utf;</em> is obsolete since any Perl 6 source code is always treated as unicode and any UTF character can be used anywhere in the code. Even the features of the pragmas <em>constant</em> and <em>vars</em> are now part of the core language.</p>
<p>
Also the functionality of many useful and famous modules like Moose (object system), Parse::RecDescent++, exception handling, <span class="nlw_phrase">List::[More]Utils<!-- wiki: {{List::[More]Utils}} --></span>, Export, English an advanced pretty printer and much more is already built in. So you get a lot extra for a little <strong>v6;</strong>.</p>
<h1 id="statements">Statements</h1>
<p>
Unless you use <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...">blocks<!-- wiki-renamed-link Perl 6 Block Tablet --></a>, a Perl program executes one statement after another in linear progression (from left to right, from up to down). They have to be separated by a semicolon (<strong>;</strong>), except before and after a closing curly brace, where it is optional.</p>
<blockquote>
$coderef = sub { fetch_data(); compute() }</blockquote>
<br /><h1 id="spaces_and_indentation">Spaces and Indentation</h1>
<p>
Perl doesn't care about indentation. And spaces are still in many places without meaning. However these have become fewer.</p>
<h1 id="comments">Comments</h1>
<h2 id="single_line">Single Line</h2>
<p>
Like in Perl 5 and many other languages of its league, a &quot;#&quot; tells the compiler to ignore the rest of the line.</p>
<blockquote>
my $var = 'good'; # that code is boring</blockquote>
<br /><h2 id="multi_line">Multi Line</h2>
<p>
If many lines has to be commented, use <strong>#`</strong> followed by any pair of braces that surround the comment.</p>
<blockquote>
$things = #`( i wonder how many of these<br />
I will need, hm maybe 3, or 4, better 5 ) 5; # same as <em>$things = 5;</em></blockquote>
<br /><h2 id="pod">POD</h2>
<p>
Even POD is there to embedd documentation, it can be used just for inserting comments.</p>
<blockquote>
=begin comment<br />
...<br />
=end comment</blockquote>
<br /><blockquote>
$=</blockquote>
<br /><p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#pod_variables">all POD variables</a><!-- wiki: "all POD variables"{link: [Perl 6 Lookup Tablet]POD Variables} --></span></p>
<h1 id="quoting">Quoting</h1>
<p>
Quoting is like <span class="nlw_phrase"><a title="inter-workspace link: perl6" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_regex_tablet">regular expression</a><!-- wiki: "regular expression"{link: [Perl 6 Regex Tablet]} --></span> a sublanguage inside the main language with its own syntactical rules. It is parsed by a special grammar as to be found in the <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#special_variables">special variable</a><!-- wiki: "special variable"{link: [perl 6 lookup tablet] Special Variables} --></span> <em>$~Quote</em>. The operator with the same name (the generic quoting operator Q) does almost nothing, just provides a mechanism to mark the beginning and end of text sequence.</p>
<h2 id="delimiter">Delimiter</h2>
<p>
The examples in this chapter use almost every time slashes for that purpose, but any not alphanumerical character or pair of matching (bracing) character can be used as well.</p>
<blockquote>
<span class="nlw_phrase">Q /.../ or Q |...| or Q *...* or Q &quot;...&quot; or Q[...] ...<!-- wiki: {{Q /.../ or Q |...| or Q *...* or Q &quot;...&quot; or Q[...] ...}} --></span></blockquote>
<br /><p>
An extended delimiter mechanism is delivered by <span class="nlw_phrase"><a title="section link" href="#heredocs">heredocs</a><!-- wiki: "heredocs"{link: Heredocs} --></span>.</p>
<h2 id="interpolation">Interpolation</h2>
<p>
Inside of these delimiters, every character will be taken literally. Any additional meaning has to be added by <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#quoting_adverbs">quoting adverbs</a><!-- wiki: "quoting adverbs"{link: [Perl 6 Lookup Tablet] Quoting Adverbs} --></span> that have to follow the Q. Most of them have a short and a long name and some of the most useful have an additional syntax that replaces them altogether with the <em>Q</em> operator (like single or double quotes).</p>
<blockquote>
:b aka :backslash # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#control_chars">control character</a><!-- wiki: "control character"{link: [Perl 6 Lookup Tablet] Control Chars} --></span> (implies at least <span class="nlw_phrase"><a title="section link" href="#single_quotes">:q</a><!-- wiki: ":q"{link: Single Quotes} --></span>)<br />
:s aka :scalar # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#scalar">scalar variable</a><!-- wiki: "scalar variable"{link: [Perl 6 Variable Tablet] Scalar} --></span>: $name<br />
:a aka :array # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#array">array variable</a><!-- wiki: "array variable"{link: [Perl 6 Variable Tablet] Array} --></span>: @name[...]<br />
:h aka :hash # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#hash">hash variable</a><!-- wiki: "hash variable"{link: [Perl 6 Variable Tablet] Hash} --></span>: %name{...}<br />
:c aka :closure # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_block_tablet#block">anonymous blocks</a><!-- wiki: "anonymous blocks"{link: [Perl 6 Block Tablet] Block} --></span>: {...}<br />
:f aka :function # <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#callable">callable routines</a><!-- wiki: "callable routines"{link: [Perl 6 Variable Tablet] Callable} --></span>: &amp;name(...)</blockquote>
<br /><blockquote>
Q :b /\t\n/; # tab and new line character<br />
Q :s /$poem/; # content of $poem<br />
Q :a /@primes[]/; # all number separated by single spaces<br />
Q :a /@primes[0]/; # returns '2', the first prime<br />
Q :a <span class="nlw_phrase">/me@primes.de/; # returns literally the mail adress, you need the square braces to interpolate arrays<!-- wiki: {{/me@primes.de/; # returns literally the mail adress, you need the square braces to interpolate arrays}} --></span><br />
Q :h /%dev{}/; # all developer names (values, not keys) separated by single spaces, <span class="nlw_phrase"><a title="section link" href="#quote_words">angle brackets</a><!-- wiki: "angle brackets"{link: Quote Words} --></span> work too<br />
Q :h /%dev[rakudo] %dev&lt;niecza&gt;/; # just 2 values<br />
Q :h /%dev/; # literally '%dev', you need braces here too<br />
Q :c /There are {2**6} hexagrams in I Ging./; # returns: 'There are 64 hexagrams in I Ging.', inserts the result of the closure<br />
Q :c /Perl 6 Compiler: {%dev.keys}./; # use it too for method calls<br />
Q :h /Perl 6 Compiler: %dev.keys./; # no interpolation<br />
Q :f :a /Here it Tom with the weather: &amp;fetch_report($day)./; # inserts report of that day, even inside Strings the correctness of arguments will be checked!<br />
Q :f :a /fetch_report($day)/; # interpolates just $day<br />
Q :f :a /&amp;fetch_report/; # literal string '&amp;fetch_report', even if the subroutine takes no arguments</blockquote>
<br /><h2 id="single_quotes">Single Quotes</h2>
<p>
They provide the most basic mechanism in a convenient syntax. All the following are synonyms:</p>
<blockquote>
Q :single /.../;<br />
Q :q /.../;<br />
q /.../;<br />
'...'</blockquote>
<br /><p>
The backslash (\) liberates here just itself and the single quote from its special meaning. Or to put it simple <em>\\</em> translates (or interpolates) to <em>\</em> and <em>\'</em> to <em>'</em>. For anything more you need additional adverbs.</p>
<blockquote>
'Welcome in Larry\'s madhouse'<br />
'\'\\'; # string contains: <strong>'\</strong><br />
q |\||; # string contains: <strong>|</strong></blockquote>
<br /><h2 id="double_quotes">Double Quotes</h2>
<p>
Double quoting combines all the previous mentioned adverbs for interpolation (also <strong>:q</strong> - implied by <strong>:b</strong>), thatswhy all the following are synonymous.</p>
<blockquote>
Q :s, :a, :h, :f, :c, :b /.../;<br />
Q :double /.../;<br />
Q :qq /.../;<br />
qq /.../;<br />
&quot;...&quot;</blockquote>
<br /><p>
But further adverbs can also be added using q/.../ or qq/.../.</p>
<h2 id="quote_words">Quote Words</h2>
<p>
While other quote operators return a single string item, this one can return <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#array">arrays</a><!-- wiki: "arrays"{link: [Perl 6 Variable Tablet]Array} --></span> because he splits the string on any whitespace (\s aka &lt;ws&gt;).</p>
<blockquote>
Q :words /.../;<br />
Q :w /.../; # :q implied<br />
qw/.../; # like Perl 5's qw/.../<br />
&lt;...&gt;</blockquote>
<br /><blockquote>
Q :quotewords /.../; # qw/.../ with quote protextion<br />
Q :ww /.../; # :qq implied<br />
&lt;&lt;&gt;&gt; # have also a unicode alias (chevron)</blockquote>
<br /><p>
The second group of aliases mark a modified version, where single and double quoted strings (inside the quote) are treated as one word. Thats called <em>quote protection</em>.</p>
<blockquote>
my @steps = &lt;one &quot;two three&quot;&gt;; # 3 steps to success: <span class="nlw_phrase">[&quot;one&quot;, &quot;\&quot;two&quot;, &quot;three\&quot;&quot;]<!-- wiki: {{[&quot;one&quot;, &quot;\&quot;two&quot;, &quot;three\&quot;&quot;]}} --></span><br />
my @steps = &lt;&lt;one &quot;two three&quot;&gt;&gt;; # now only 2 steps: <span class="nlw_phrase">[&quot;one&quot;, &quot;two three&quot;]<!-- wiki: {{[&quot;one&quot;, &quot;two three&quot;]}} --></span></blockquote>
<br /><p>
Please note also that <strong>:quotewords</strong> (double pointy braces) implies <strong>:double</strong> (double quotes), which means all <span class="nlw_phrase"><a title="section link" href="#interpolation">interpolation rules</a><!-- wiki: "interpolation rules"{link: Interpolation} --></span> apply here also.</p>
<blockquote>
&lt;$pi&gt; eq '$pi'<br />
&lt;&lt;$pi&gt;&gt; eq &quot;$pi&quot; # == '3.14159...'</blockquote>
<br /><p>
The same pointy braces (quote operators) are also in used, when writing <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#hash_slices">hash slices</a><!-- wiki: "hash slices"{link: [Perl 6 Variable Tablet]Hash Slices} --></span>.</p>
<h2 id="heredocs">Heredocs</h2>
<p>
Are now normal quoted strings, only with a special delimiter, defined by the adverbs <strong>to</strong> and heredoc. Heredocs can be nested.</p>
<blockquote>
Q :to 'EOT';<br />
...<br />
...<br />
EOT</blockquote>
<br /><p>
To make templates in which variables and closures are evaluated, take the normal double quote and just add the adverb for the heredoc delimiter or define with other adverbs what exactly you want to have evaluated.</p>
<blockquote>
qq:heredoc 'EOT';<br />
EOT</blockquote>
<br /><h2 id="paths">Paths</h2>
<p>
Pathstrings have their own quote operator. This way you get the warnings early if there is something incompatible with convention.</p>
<blockquote>
Q :path /.../;<br />
Q :p /.../;<br />
qp /.../;</blockquote>
<br /><h2 id="regex">Regex</h2>
<p>
Even being a completely different language then quoting on its own (as to be defined in <em>$~Regex</em> and <em>$~P5Regex</em>), <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...">regular expressions<!-- wiki-renamed-link Perl 6 Regex Tablet --></a> can be built using the general quoting operator with the right adverb.</p>
<blockquote>
Q :regex /.../ aka rx/.../<br />
Q :subst /.../.../ aka s/.../.../<br />
Q :trans /.../.../ aka tr/.../.../ aka .trans(&quot;...&quot; =&gt; &quot;...&quot;)</blockquote>
<br /><h2 id="code">Code</h2>
<p>
The following 3 aliases quote code that will be run immediately (on runtime) and replaced with the result.</p>
<blockquote>
Q :exec /.../;<br />
Q :x /.../;<br />
qx /.../;</blockquote>
<br /><p>
In Perl 5 qx/.../ aka <tt>...</tt> did a system call and not just run eval. To get that behaviour use:</p>
<blockquote>
qqx/$cmd @args[]/ # do system call and insert result, alias to that is gone</blockquote>
<br /><p>
However there is yet another adverb for quasi quoting, meaning: the quoted code will be parsed and compiled into a abstract syntax tree (AST - internal representation of the compiler) during compile time. Result is the compiled AST. Parsing will be done by using the grammar stored in <em>$~Quasi</em>. This gets important when writing <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_meta_tablet#macros">macros</a><!-- wiki: "macros"{link: [Perl 6 Meta Tablet] Macros} --></span>.</p>
<blockquote>
Q :code /.../;</blockquote>
<br /><h1 id="number_literals">Number Literals</h1>
<p>
Unlike strings, numbers don't need <span class="nlw_phrase"><a title="section link" href="#quoting">quoting</a><!-- wiki: "quoting"{link: Quoting} --></span>. But if there is a non number character in it, there will be an error. Chars of a number definition are: (0-9,.,+,-,e,E,i,_) including the <span class="nlw_phrase"><a title="section link" href="#radix_prefixes">radix prefixes</a><!-- wiki: "radix prefixes"{link: Radix Prefixes} --></span>: (0b,0o,0d,0x) and the prefix for <span class="nlw_phrase"><a title="section link" href="#version_number">version numbering</a><!-- wiki: "version numbering"{link: Version Number} --></span> (v). The + and can act also as operator that convert into the numerical context, which still means: take from left to right all digits and stop with the first none number character.</p>
<p>
A single underscore is allowed only between any two digits, delimiter helping readability.</p>
<blockquote>
3_456_789; # same as 3456789</blockquote>
<br /><blockquote>
$int = 2;<br />
$real = 2.2;</blockquote>
<br /><h2 id="radix_prefixes">Radix Prefixes</h2>
<blockquote>
0b binary - base 2, digits 0..1<br />
0o ocatal - base 8, digits 0..7<br />
0d decimal - base 10, digits 0..9<br />
0x hexadecimal - base 16, digits 0..9,a..f (case insensitive)</blockquote>
<br /><h2 id="general_radix_form">General Radix Form</h2>
<blockquote>
:10&lt;42&gt; # same as 0d42 or 42</blockquote>
<br /><h2 id="scientific_notation">Scientific Notation</h2>
<blockquote>
$float = 60.2e23 # becomes automatically 6.02e24<br />
$float = 6.02E-23 # capital E works too</blockquote>
<br /><h2 id="rational_number">Rational Number</h2>
<p>
To distinguish them from a division operation, you have to groupe them with braces.</p>
<blockquote>
(3/7)<br />
(3/7).numerator<br />
(3/7).denominator<br />
(3/7).nude.perl</blockquote>
<br /><p>
As always, <span class="nlw_phrase"><a title="section link" href="#perl">.perl</a><!-- wiki: ".perl"{link: perl} --></span> gives you an almost source like code formatting which results here in <em>3/7</em>. Adding <strong>.nude</strong> you get <em>(3/7)</em>, the nude source code. There are 2 different <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#immutable_types">immutable value types</a><!-- wiki: "immutable value types"{link: [perl 6 lookup tablet] immutable types} --></span> representing both rational number. FatRat has <em>unlimited</em> precision and Rat has just enough to be evaled into a <em>Real</em> type. When you explicitly <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_variable_tablet#data_types">type a variable</a><!-- wiki: "type a variable"{link: [perl 6 variable tablet] data types} --></span> to one o them, the braces become optional.</p>
<blockquote>
my Rat $pi_approx = 22/7;<br />
my FatRat $pi_approx = 2222222222/6981317007; # much more precision</blockquote>
<br /><h2 id="complex_number">Complex Number</h2>
<p>
have also there own <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_lookup_tablet#immutable_types">immutable value type</a><!-- wiki: "immutable value type"{link: [perl 6 lookup tablet] immutable types} --></span>.</p>
<blockquote>
1+2i<br />
my $c = 5.2+1e42i;<br />
say $c.WHAT; # returns 'Complex', which is the classname of the value object</blockquote>
<br /><h2 id="version_number">Version Number</h2>
<blockquote>
v1.2.3 # okay<br />
v1.2.* # okay, wildcard version<br />
v1.2.3+ # okay, wildcard version<br />
v1.2.3beta # illegal<br />
Version('1.2.3beta') # okay</blockquote>
<br /><h1 id="formatting">Formatting</h1>
<h2 id="perl">perl</h2>
<p>
The .perl method returns a string that arranges any set of values in almost the same format, as the would be defined it source code. It's a built in Data::Dumper (pretty printer).</p>
<blockquote>
@a.perl # evals to: <span class="nlw_phrase">[1, 2, 3, 4, 5]<!-- wiki: {{[1, 2, 3, 4, 5]}} --></span><br />
%h.perl # evals to: {&quot;akey&quot; =&gt; &quot;avalue&quot;, &quot;bkey&quot; =&gt; &quot;bvalue&quot;}</blockquote>
<br /><p>
This works with data of any nesting depth.</p>
<h2 id="pretty">pretty</h2>
<h2 id="fmt">fmt</h2>
<p>
Small brother of sprinf that works as a method of a variable. If thats a pair or list it formats of course several values in the same way with same syntax as sprinf.</p>
<blockquote>
$result = '5.123456789';<br />
say $result.fmt('%.2f'); # &quot;5.12\n&quot; <br />
@nr = 1..5;<br />
say @nr.fmt(&quot;+%d.&quot;); # &quot;+1.+2.+3.+4.+5.\n&quot;<br />
say @nr.fmt(&quot;%d.&quot;,','); # &quot;1.,2.,3.,4.,5.\n&quot;<br />
say @nr.fmt(&quot;%d %d&quot;); # ERROR<br />
%p6c = sorear =&gt; 'niecza', fglock =&gt; 'perlito';<br />
say %p6c.fmt(&quot;%s!&quot;); # &quot;sorear!\nfglock!\n&quot;<br />
say %p6c.fmt(&quot;%s&quot;,','); # &quot;sorear,fglock!\n&quot;<br />
say %p6c.fmt(&quot;%s:%s&quot;); # &quot;sorear:niecza\nfglock:perlito\n&quot;<br />
say %p6c.fmt(&quot;%s:%s&quot;,); # &quot;sorear:niecza,fglock:perlito\n&quot;<br />
say %p6c.fmt(&quot;%s %s %s&quot;); # ERROR</blockquote>
<br /><h2 id="sprintf">sprintf</h2>
<p>
Since Algol68 known function, that inserts into a string any number of special formatted values.</p>
<h2 id="pack">pack</h2>
<h2 id="formats">Formats</h2>
<p>
moved from core language to a module.</p>
<h2 id="date_and_time">Date and Time</h2>
<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> <strong><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> <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_basics_tablet</guid>
<pubDate>Tue, 17 Apr 2012 00:54:12 -0000</pubDate>
</item>

</channel>
</rss>