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

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

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

<item>
<title><![CDATA[Best Of Perl 6 Tablet]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?best_of_perl_6_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> <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> <strong><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></strong> <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="#command_line">Command Line</a><!-- wiki: {link: [] Command Line} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#file_io">File IO</a><!-- wiki: {link: [] File IO} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#automatic_multithreading">Automatic multithreading</a><!-- wiki: {link: [] Automatic multithreading} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#comparison">Comparison</a><!-- wiki: {link: [] Comparison} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#case_construct">Case construct</a><!-- wiki: {link: [] Case construct} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#powerful_for_loops">Powerful for loops</a><!-- wiki: {link: [] Powerful for loops} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#named_parameters_in_subroutines">Named parameters in subroutines</a><!-- wiki: {link: [] Named parameters in subroutines} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="#objects_with_auto_generated_new_and_getters_and_setters">Objects with auto generated new and getters and setters</a><!-- wiki: {link: [] Objects with auto generated new and getters and setters} --></span></li>
</ul>
</div>
</td></tr></table><!-- wiki: {toc: } --></div><br /><br /><p>
This is a small tour, showing the best features and improvements of Perl 6 in short examples, compared to similar working Perl 5 examples.</p>
<h3 id="command_line">Command Line</h3>
<p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_io_tablet#command_line">Making output</a><!-- wiki: "Making output"{link: [Perl 6 IO Tablet]Command Line} --></span> will become simpler and easier for newbies.</p>
<pre>
               Perl 5                                     Perl 6 
 print &quot;bananas are good\n&quot;;                     say &quot;bananas are good&quot;;
 print &quot;and I said: $quotes{\&quot;me\&quot;}\n&quot;;          say &quot;and I said: %quotes{&quot;me&quot;}.&quot;;
 print &quot;and I said: $quotes{\&quot;me\&quot;}\n&quot;;          say &quot;and I said: %quotes&lt;me&gt;.&quot;;
 print &quot;What is ... &quot;;                           $result = prompt &quot;What is ... &quot;;
 chomp($result = &lt;&gt;);
</pre>
<br /><h3 id="file_io">File IO</h3>
<p>
File::Slurp is in the Perl 6 core language and <span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_io_tablet#file">file reading</a><!-- wiki: "file reading"{link: [Perl 6 IO Tablet]File} --></span> is simpler then ever (and autochomp included).</p>
<pre>
               Perl 5                                     Perl 6 
 $content = do { local $/;                       $content = slurp &quot;poetry.txt&quot;;
    open my $FH, &quot;poetry.txt&quot;; &lt;$FH&gt;
 };

chomp(@content = do {                            @content = lines &quot;poetry.txt&quot;;
    open my $FH, &quot;poetry.txt&quot;; &lt;$FH&gt;
});
</pre>
<br /><h3 id="automatic_multithreading">Automatic multithreading</h3>
<p>
Applying operations to junctions and arrays is now syntactically compact and readable. Perl 6 will create threads where appropriate to use multiple processors, cores or hyperthreading for high level language SIMD concurrent processing.</p>
<pre>
               Perl 5                                     Perl 6 
 my $sum;                                        my $sum = [+] @numbers;
 $sum += $_ for @numbers;
 for (0 .. $#factor1) {                          @product = @factor1 &gt;&gt;*&lt;&lt; @factor2;
   $product[$] = $factor1[$] * $factor2[$_];
 }
</pre>
<br /><p>
The Perl 5 code is a simplification, of course Perl6 &quot;does the right thing&quot; when the arrays have different lengths.</p>
<h3 id="comparison">Comparison</h3>
<p>
Here are junctions, then chained comparison operators.</p>
<pre>
               Perl 5                                     Perl 6 
 if ($a == 3 or $a == 4 or $a == 7) {...}        if $a = 3 | 4 | 7 {...}
 if (4 &lt; $a and $a &lt; 12) {...}                   if 4 &lt; $a &lt; 12 {...} 
 if (4 &lt; $a and $a &lt;= 12) {...}                  if $a ~~ 4^..12 {...}
 $a = defined $b ? $b : $c;                      $a = $b // $c;
</pre>
<br /><p>
The defined-OR operator eases lot of cases where Perl 5 newbies could fall into traps.</p>
<h3 id="case_construct">Case construct</h3>
<pre>
               Perl 5                                      Perl 6 
                                                     given $a {
 if ($a == 2 or $a == 5) {...} }}                      when 2 | 5 {...}
 elsif ($a == 6 or $a == 7 or $a == 8 or $a == 9) {}   when 6 .. 9 {...} 
 elsif ($a =~ /g/) {...}                               when 'g' {...}
 else {...}                                            default {...}
                                                     }
</pre>
<br /><p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_block_tablet#given">That new construct</a><!-- wiki: "That new construct"{link: [Perl 6 Block Tablet]given} --></span> (backported to 5.10) is clear to read, very versatile and when used in combination with junctions, becomes even clearer.</p>
<h3 id="powerful_for_loops">Powerful for loops</h3>
<p>
<span class="nlw_phrase"><a title="section link" href="http://www.perlfoundation.org/perl6/index.cgi?perl_6_block_tablet#for">List iteration via for</a><!-- wiki: "List iteration via for"{link: [Perl 6 Block Tablet]for} --></span> is now much more versatile.</p>
<pre>
               Perl 5                                     Perl 6 
 for my $i (0..15) {...}                         for ^16 -&gt; $i {...}
 for (my $i=15; $i&gt;1; $i-2) {...}                for 15,*-2...1 -&gt; $i {...}
 for my $key (keys %hash) {                      for %hash.kv -&gt; $key, $value {
   print &quot;$key =&gt; $hash{$key}\n&quot;; ...              say &quot;$key =&gt; $value&quot;; ...
 for my $i (0..$#a) {                            for zip(@a; @b; @c) -&gt; $a, $b, $c {...}
   my $a = @a[$i];
   my $b = @b[$i];
   my $c = @c[$i]; ... 
</pre>
<br /><h3 id="named_parameters_in_subroutines">Named parameters in subroutines</h3>
<pre>
               Perl 5                                     Perl 6 
 sub routine {                                   sub routine ($a, $b, *@rest) {...}
   my $a = shift;
   my $b = shift;
   my @rest = @_;
 }
</pre>
<br /><h3 id="objects_with_auto_generated_new_and_getters_and_setters">Objects with auto generated new and getters and setters</h3>
<p>
Simple Object creation is now as easy as it gets.</p>
<pre>
               Perl 5                                     Perl 6 
 package Heart::Gold;                            class Heart::Gold {
                                                   has $.speed;
 sub new {                                         method stop { $.speed = 0 }      
   bless {speed =&gt; 0 }, shift;                   }  
 }                                               
                                                 my Heart::Gold $hg1 .= new;
 sub speed {                                     $hg1.speed = 100;
   my $self = shift;                             my $hg2 = $hg1.clone;
   my $speed = shift;
   if (defined $speed) { $self-&gt;{speed} = $speed }
   else { $self-&gt;{speed} }
 }

 sub stop {
   my $self = shift; 
   $self-&gt;{speed} = 0;
 }
</pre>
<br /><p>
The new, getter, setter and clone methods are auto generated. Methods now are called &quot;method&quot;.</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> <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> <strong><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></strong> <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?best_of_perl_6_tablet</guid>
<pubDate>Tue, 17 Apr 2012 00:59:45 -0000</pubDate>
</item>

</channel>
</rss>