Commits

Shlomi Fish committed c342cf8

Add the hyperpolyglot.

Comments (0)

Files changed (5)

                     title => "Book for Quickly Learning Perl (based on previous knowledge)",
                 },
                 {
+                    text => "Hyperpolyglot",
+                    url => "tutorials/hyperpolyglot/",
+                    title => "Our mirror for the lingo of Perl and other languages under CC-by-sa",
+                    subs =>
+                    [
+                        {
+                            text => "Sheet 1",
+                            url => "tutorials/hyperpolyglot/sheet1.html",
+                        },
+                        {
+                            text => "Sheet 2",
+                            url => "tutorials/hyperpolyglot/sheet2.html",
+                        },
+                    ],
+                },
+                {
                     text => "Elements to Avoid",
                     url => "tutorials/bad-elements/",
                     title => "Elements of Perl that should be avoided and what to replace them with",

lib/retrieved-html-parts/hyperpolyglot/scripting.html

+            <div id="content-wrap">
+
+                <!-- google_ad_section_end -->
+
+                <div id="main-content">
+                    <div id="action-area-top"></div>
+
+                    <!-- google_ad_section_start -->
+                                                                    <div id="page-title">
+                        Interpreted Languages: PHP, Perl, Python, Ruby (Sheet One)                        </div>
+
+
+
+
+
+                        <div id="page-content">
+
+
+
+<p><a name="top"></a><em>a side-by-side reference sheet</em></p>
+<p>sheet one: <a href="#grammar-invocation">grammar and invocation</a> | <a href="#var-expr">variables and expressions</a> | <a href="#arithmetic-logic">arithmetic and logic</a> | <a href="#strings">strings</a> | <a href="#regexes">regexes</a> | <a href="#dates-time">dates and time</a><br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="#arrays">arrays</a> | <a href="#dictionaries">dictionaries</a> | <a href="#functions">functions</a> | <a href="#execution-control">execution control</a></p>
+<p><a href="http://hyperpolyglot.org/scripting2">sheet two</a>: <a href="http://hyperpolyglot.org/scripting2#file-handles">file handles</a> | <a href="http://hyperpolyglot.org/scripting2#files">files</a> | <a href="http://hyperpolyglot.org/scripting2#directories">directories</a> | <a href="http://hyperpolyglot.org/scripting2#processes-environment">processes and environment</a> | <a href="http://hyperpolyglot.org/scripting2#libraries-modules">libraries and modules</a> | <a href="http://hyperpolyglot.org/scripting2#objects">objects</a> | <a href="http://hyperpolyglot.org/scripting2#reflection">reflection</a><br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <a href="http://hyperpolyglot.org/scripting2#net-web">net and web</a> | <a href="http://hyperpolyglot.org/scripting2#unit-tests">unit tests</a> | <a href="http://hyperpolyglot.org/scripting2#debugging-profiling">debugging and profiling</a> | <a href="http://hyperpolyglot.org/scripting2#java-interop">java interop</a> | <em><a href="http://hyperpolyglot.org/contact">contact</a></em><br></p>
+<table class="wiki-content-table">
+<tbody><tr>
+<th><a name="general"></a></th>
+<th><a href="#php">php</a></th>
+<th><a href="#perl">perl</a></th>
+<th><a href="#python">python</a></th>
+<th><a href="#ruby">ruby</a></th>
+</tr>
+<tr>
+<td><a name="version-used"></a><a href="#version-used-note">versions used</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>5.3</em></span></td>
+<td><span style="color: gray"><em>5.12; 5.14</em></span></td>
+<td><span style="color: gray"><em>2.7; 3.2</em></span></td>
+<td><span style="color: gray"><em>1.8; 1.9</em></span></td>
+</tr>
+<tr>
+<td><a name="implicit-prologue"></a><a href="#implicit-prologue-note">implicit prologue</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">strict</span>;</td>
+<td><span style="color: purple">import</span> os, re, sys</td>
+<td><span style="color: gray"><em>none</em></span></td>
+</tr>
+<tr>
+<td><a name="version"></a><a href="#version-note">show version</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$ php <span style="white-space: pre-wrap;">--</span>version</td>
+<td>$ perl <span style="white-space: pre-wrap;">--</span>version</td>
+<td>$ python -V</td>
+<td>$ ruby <span style="white-space: pre-wrap;">--</span>version</td>
+</tr>
+<tr>
+<th colspan="5"><a name="grammar-invocation"></a><a href="#grammar-invocation-note">grammar and invocation</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="interpreter"></a><a href="#interpreter-note">interpreter</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$ php -f foo.php</td>
+<td>$ perl foo.pl</td>
+<td>$ python foo.py</td>
+<td>$ ruby foo.rb</td>
+</tr>
+<tr>
+<td><a name="repl"></a><a href="#repl-note">repl</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$ php</td>
+<td>$ perl -de 0</td>
+<td>$ python</td>
+<td>$ irb</td>
+</tr>
+<tr>
+<td><a name="cmd-line-program"></a><a href="#cmd-line-program-note">command line program</a></td>
+<td>$ php -r 'echo "hi\n";'</td>
+<td>$ perl -e 'print("hi\n")'</td>
+<td>$ python -c "print('hi')"</td>
+<td>$ ruby -e 'puts "hi"'</td>
+</tr>
+<tr>
+<td><a name="block-delimiters"></a><a href="#block-delimiters-note">block delimiters</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>{}</td>
+<td>{}</td>
+<td>: <span style="color: gray"><em>and offside rule</em></span></td>
+<td>{}<br>
+<span style="color: purple">do end</span></td>
+</tr>
+<tr>
+<td><a name="statement-separator"></a><a href="#statement-separator-note">statement separator</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>;<br>
+<br>
+<span style="color: gray"><em>statements must be semicolon terminated inside {}</em></span></td>
+<td>;</td>
+<td><span style="color: gray"><em>newline or</em></span> ;<br>
+<br>
+<span style="color: gray"><em>newlines not separators inside (), [], {}, triple quote literals, or after backslash: <span style="white-space: pre-wrap;">\</span></em></span></td>
+<td><span style="color: gray"><em>newline or</em></span> ;<br>
+<br>
+<span style="color: gray"><em>newlines not separators inside (), [], {}, <span style="white-space: pre-wrap;">``</span>, '', "", or after binary operator or backslash: <span style="white-space: pre-wrap;">\</span></em></span></td>
+</tr>
+<tr>
+<td><a name="eol-comment"></a><a href="#eol-comment-note">end-of-line comment</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><span style="white-space: pre-wrap;">//</span> comment<br>
+# comment</span></td>
+<td><span style="color: gray"># comment</span></td>
+<td><span style="color: gray"># comment</span></td>
+<td><span style="color: gray"># comment</span></td>
+</tr>
+<tr>
+<td><a name="multiple-line-comment"></a><a href="#multiple-line-comment-note">multiple line comment</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray">/* comment line<br>
+another line */</span></td>
+<td><span style="color: gray">=for<br>
+comment line<br>
+another line<br>
+=cut</span></td>
+<td><span style="color: gray"><em>use triple quote string literal:</em></span><br>
+<span style="color: maroon">'''comment line<br>
+another line'''</span></td>
+<td><span style="color: gray">=begin<br>
+comment line<br>
+another line<br>
+=end</span></td>
+</tr>
+<tr>
+<th colspan="5"><a name="var-expr"></a><a href="#var-expr-note">variables and expressions</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="local-var"></a><a href="#local-var-note">local variable</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"># in function body:</span><br>
+$<span style="color: peru">v</span> = <span style="color: teal">NULL</span>;<br>
+$<span style="color: peru">a</span> = array();<br>
+$<span style="color: peru">d</span> = array();<br>
+$<span style="color: peru">x</span> = 1;<br>
+list($<span style="color: peru">y</span>, $<span style="color: peru">z</span>) = array(2, 3);</td>
+<td><span style="color: purple">my</span> <span style="color: peru">$v</span>;<br>
+<span style="color: purple">my</span> (<span style="color: teal">@a</span>, <span style="color: teal">%d</span>);<br>
+<span style="color: purple">my</span> <span style="color: peru">$x</span> = 1;<br>
+<span style="color: purple">my</span> (<span style="color: peru">$y</span>, <span style="color: peru">$z</span>) = (2, 3);</td>
+<td><span style="color: gray"># in function body:</span><br>
+<span style="color: peru">v</span> = <span style="color: teal">None</span><br>
+<span style="color: peru">a</span>, <span style="color: peru">d</span> = [], {}<br>
+<span style="color: peru">x</span> = 1<br>
+<span style="color: peru">y</span>, <span style="color: peru">z</span> = 2, 3</td>
+<td>v = <span style="color: peru">nil</span><br>
+a, d = [], {}<br>
+x = 1<br>
+y, z = 2, 3</td>
+</tr>
+<tr>
+<td><a name="local-scope-regions"></a><a href="#local-scope-regions-note">regions which define lexical scope</a></td>
+<td><span style="color: gray"><em>top level:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>function or method body<br>
+<br>
+nestable (with use clause):<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>anonymous function body</em></span></td>
+<td><span style="color: gray"><em>top level:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>file<br>
+<br>
+nestable:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>function body<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>anonymous function body<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>anonymous block</em></span></td>
+<td><span style="color: gray"><em>nestable (read only):<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>function or method body</em></span></td>
+<td><span style="color: gray"><em>top level:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>file<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>class block<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>module block<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>method body<br>
+<br>
+nestable:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>anonymous function body<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>anonymous block</em></span></td>
+</tr>
+<tr>
+<td><a name="global-var"></a><a href="#global-var-note">global variable</a></td>
+<td>list($<span style="color: peru">g1</span>, $<span style="color: peru">g2</span>) = array(7, 8);<br>
+<br>
+<span style="color: purple">function</span> <span style="color: #0000cd">swap_globals</span>() {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">global</span> $<span style="color: peru">g1</span>, $<span style="color: peru">g2</span>;<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>list($<span style="color: peru">g1</span>, $<span style="color: peru">g2</span>) = array($<span style="color: peru">g2</span>, $<span style="color: peru">g1</span>);<br>
+}</td>
+<td><span style="color: purple">our</span> (<span style="color: peru">$g1</span>, <span style="color: peru">$g2</span>) = (7, 8);<br>
+<br>
+<span style="color: purple">sub</span> <span style="color: #0000cd">swap_globals</span> {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>($g1, $g2) = ($g2, $g1);<br>
+}</td>
+<td><span style="color: peru">g1</span>, <span style="color: peru">g2</span> = 7, 8<br>
+<br>
+<span style="color: purple">def</span> <span style="color: #0000cd">swap_globals</span>():<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">global</span> g1, g2<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>g1, g2 = g2, g1</td>
+<td><span style="color: peru">$g1</span>, <span style="color: peru">$g2</span> = 7, 8<br>
+<br>
+<span style="color: purple">def</span> <span style="color: #0000cd">swap_globals</span><br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: peru">$g1</span>, <span style="color: peru">$g2</span> = <span style="color: peru">$g2</span>, <span style="color: peru">$g1</span><br>
+end</td>
+</tr>
+<tr>
+<td><a name="const"></a><a href="#const-note">constant</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>define(<span style="color: maroon">"PI"</span>, 3.14);</td>
+<td><span style="color: purple">use</span> <span style="color: #0000cd">constant</span> <span style="color: purple">PI</span> =&gt; 3.14;</td>
+<td><span style="color: gray"># uppercase identifiers<br>
+# constant by convention</span><br>
+<span style="color: peru">PI</span> = 3.14</td>
+<td><span style="color: gray"># warning if capitalized<br>
+# identifier is reassigned</span><br>
+<span style="color: green">PI</span> = 3.14</td>
+</tr>
+<tr>
+<td><a name="assignment"></a><a href="#assignment-note">assignment</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">v</span> = 1;</td>
+<td>$v = 1;</td>
+<td><span style="color: gray"><em>assignments can be chained but otherwise don't return values:</em></span><br>
+<span style="color: peru">v</span> = 1</td>
+<td>v = 1</td>
+</tr>
+<tr>
+<td><a name="parallel-assignment"></a><a href="#parallel-assignment-note">parallel assignment</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>list($<span style="color: peru">x</span>, $<span style="color: peru">y</span>, $<span style="color: peru">z</span>) = array(1 ,2, 3);<br>
+<br>
+<span style="color: gray"># 3 is discarded:</span><br>
+list($<span style="color: peru">x</span>, $<span style="color: peru">y</span>) = array(1, 2, 3);<br>
+<br>
+<span style="color: gray"># $z set to NULL:</span><br>
+list($<span style="color: peru">x</span>, $<span style="color: peru">y</span>, $<span style="color: peru">z</span>) = array(1, 2);</td>
+<td>($x, $y, $z) = (1, 2, 3);<br>
+<br>
+<span style="color: gray"># 3 is discarded:</span><br>
+($x, $y) = (1, 2, 3);<br>
+<br>
+<span style="color: gray"># $z set to undef:</span><br>
+($x, $y, $z) = (1, 2);</td>
+<td><span style="color: peru">x</span>, <span style="color: peru">y</span>, <span style="color: peru">z</span> = 1, 2, 3<br>
+<br>
+<span style="color: gray"># raises ValueError:</span><br>
+<span style="color: peru">x</span>, <span style="color: peru">y</span> = 1, 2, 3<br>
+<br>
+<span style="color: gray"># raises ValueError:</span><br>
+<span style="color: peru">x</span>, <span style="color: peru">y</span>, <span style="color: peru">z</span> = 1, 2</td>
+<td>x, y, z = 1, 2, 3<br>
+<br>
+<span style="color: gray"># 3 is discarded:</span><br>
+x, y = 1, 2, 3<br>
+<br>
+<span style="color: gray"># z set to nil:</span><br>
+x, y, z = 1, 2</td>
+</tr>
+<tr>
+<td><a name="swap"></a><a href="#swap-note">swap</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>list($<span style="color: peru">x</span>, $<span style="color: peru">y</span>) = array($y, $x);</td>
+<td>($x, $y) = ($y, $x);</td>
+<td><span style="color: peru">x</span>, <span style="color: peru">y</span> = y, x</td>
+<td>x, y = y, x</td>
+</tr>
+<tr>
+<td><a name="compound-assignment"></a><a href="#compound-assignment-note">compound assignment</a><br>
+<span style="color: gray"><em>arithmetic, string, logical, bit</em></span></td>
+<td>+= -= *= <span style="color: gray"><em>none</em></span> /= %= <span style="white-space: pre-wrap;">**</span>=<br>
+.= <span style="color: gray"><em>none</em></span><br>
+&amp;= |= <span style="color: gray"><em>none</em></span><br>
+<span style="white-space: pre-wrap;">&lt;&lt;= &gt;&gt;= </span>&amp;= |= ^=</td>
+<td>+= -= *= <span style="color: gray"><em>none</em></span> /= %= <span style="white-space: pre-wrap;">**</span>=<br>
+.= x=<br>
+&amp;&amp;= <span style="white-space: pre-wrap;">||</span>= ^=<br>
+<span style="white-space: pre-wrap;">&lt;&lt;= &gt;&gt;= </span>&amp;= |= ^=</td>
+<td><span style="color: gray"># do not return values:</span><br>
++= -= *= /= <span style="white-space: pre-wrap;">//</span>= %= <span style="white-space: pre-wrap;">**</span>=<br>
++= *=<br>
+&amp;= <span style="white-space: pre-wrap;">|</span>= ^=<br>
+<span style="white-space: pre-wrap;">&lt;&lt;= &gt;&gt;= </span>&amp;= |= ^=</td>
+<td>+= -= *= /= <span style="color: gray"><em>none</em></span> %= <span style="white-space: pre-wrap;">**</span>=<br>
++= *=<br>
+&amp;&amp;= <span style="white-space: pre-wrap;">||</span>= ^=<br>
+<span style="white-space: pre-wrap;">&lt;&lt;= &gt;&gt;= </span>&amp;= |= ^=</td>
+</tr>
+<tr>
+<td><a name="incr-decr"></a><a href="#incr-decr-note">increment and decrement</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">x</span> = 1;<br>
+$<span style="color: peru">y</span> = ++$<span style="color: peru">x</span>;<br>
+$<span style="color: peru">z</span> = <span style="white-space: pre-wrap;">--</span>$<span style="color: peru">y</span>;</td>
+<td><span style="color: purple">my</span> <span style="color: peru">$x</span> = 1;<br>
+<span style="color: purple">my</span> <span style="color: peru">$y</span> = ++$x;<br>
+<span style="color: purple">my</span> <span style="color: peru">$z</span> = <span style="white-space: pre-wrap;">--</span>$y;</td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>x = 1<br>
+<span style="color: gray"># x and y not mutated:</span><br>
+y = x.succ<br>
+z = y.pred</td>
+</tr>
+<tr>
+<td><a name="null"></a><a href="#null-note">null</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: teal">NULL</span> <span style="color: gray"># case insensitive</span></td>
+<td><span style="color: green">undef</span></td>
+<td><span style="color: teal">None</span></td>
+<td><span style="color: peru">nil</span></td>
+</tr>
+<tr>
+<td><a name="null-test"></a><a href="#null-test-note">null test</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>is_null($<span style="color: peru">v</span>)<br>
+! isset($<span style="color: peru">v</span>)</td>
+<td>! <span style="color: green">defined</span> $v</td>
+<td>v == <span style="color: teal">None</span><br>
+v <span style="color: purple">is</span> <span style="color: teal">None</span></td>
+<td>v == <span style="color: peru">nil</span><br>
+v.nil?</td>
+</tr>
+<tr>
+<td><a name="undef-access"></a><a href="#undef-access-note">undefined variable access</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: teal">NULL</span></td>
+<td><span style="color: gray"><em>error under</em> use strict; <em>otherwise</em> undef</span></td>
+<td><span style="color: gray"><em>raises</em> NameError</span></td>
+<td><span style="color: gray"><em>raises</em> NameError</span></td>
+</tr>
+<tr>
+<td><a name="conditional-expr"></a><a href="#conditional-expr-note">conditional expression</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">x</span> &gt; 0 ? $<span style="color: peru">x</span> : -$<span style="color: peru">x</span></td>
+<td>$x &gt; 0 ? $x : -$x</td>
+<td>x <span style="color: purple">if</span> x &gt; 0 <span style="color: purple">else</span> -x</td>
+<td>x &gt; 0 ? x : -x</td>
+</tr>
+<tr>
+<th colspan="5"><a name="arithmetic-logic"></a><a href="#arithmetic-logic-note">arithmetic and logic</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="true-false"></a><a href="#true-false-note">true and false</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: teal">TRUE FALSE</span> <span style="color: gray"># case insensitve</span></td>
+<td>1 <span style="color: maroon">""</span></td>
+<td><span style="color: purple">True False</span></td>
+<td><span style="color: peru">true false</span></td>
+</tr>
+<tr>
+<td><a name="falsehoods"></a><a href="#falsehoods-note">falsehoods</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: teal">FALSE NULL</span> 0&nbsp;0.0 <span style="color: maroon">"" "0"</span> array()</td>
+<td><span style="color: green">undef</span> 0&nbsp;0.0 <span style="color: maroon">"" "0"</span> ()</td>
+<td><span style="color: purple">False</span> <span style="color: teal">None</span> 0&nbsp;0.0 <span style="color: maroon">''</span> [] {}</td>
+<td><span style="color: peru">false nil</span></td>
+</tr>
+<tr>
+<td><a name="logical-op"></a><a href="#logical-op-note">logical operators</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>&amp;&amp; <span style="white-space: pre-wrap;">||</span> !<br>
+<span style="color: gray"><em>lower precedence:</em></span><br>
+<span style="color: purple">and or xor</span></td>
+<td>&amp;&amp; <span style="white-space: pre-wrap;">||</span> !<br>
+<span style="color: gray"><em>lower precedence:</em></span><br>
+<span style="color: green">and or xor not</span></td>
+<td><span style="color: purple">and or not</span></td>
+<td>&amp;&amp; <span style="white-space: pre-wrap;">||</span> !<br>
+<span style="color: gray"><em>lower precedence:</em></span><br>
+<span style="color: purple">and or not</span></td>
+</tr>
+<tr>
+<td><a name="relational-op"></a><a href="#relational-op-note">relational operators</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>== != <span style="color: gray"><em>or</em></span> &lt;&gt; &gt; &lt; &gt;= &lt;=<br>
+<span style="color: gray"><em>no conversion:</em></span> === !==</td>
+<td><span style="color: gray"><em>numbers only:</em></span> == != &gt; &lt; &gt;= &lt;=<br>
+<span style="color: gray"><em>strings:</em></span> <span style="color: green">eq ne gt lt ge le</span></td>
+<td><span style="color: gray"><em>relational operators are chainable:</em></span><br>
+== != &gt; &lt; &gt;= &lt;=</td>
+<td>== != &gt; &lt; &gt;= &lt;=</td>
+</tr>
+<tr>
+<td><a name="min-max"></a><a href="#min-max-note">min and max</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>min(1,2,3)<br>
+max(1,2,3)<br>
+$<span style="color: peru">a</span> = array(1,2,3)<br>
+min($<span style="color: peru">a</span>)<br>
+max($<span style="color: peru">a</span>)</td>
+<td><span style="color: purple">use</span> <span style="color: #0000cd">List::Util</span> <span style="color: green">qw</span>(min max);<br>
+<br>
+min(1,2,3);<br>
+max(1,2,3);<br>
+<br>
+<span style="color: teal">@a</span> = (1,2,3);<br>
+min(<span style="color: teal">@a</span>);<br>
+max(<span style="color: teal">@a</span>);</td>
+<td><span style="color: purple">min</span>(1,2,3)<br>
+<span style="color: purple">max</span>(1,2,3)<br>
+<br>
+<span style="color: purple">min</span>([1,2,3])<br>
+<span style="color: purple">max</span>([1,2,3])</td>
+<td>[1,2,3].min<br>
+[1,2,3].max</td>
+</tr>
+<tr>
+<td><a name="3-val-comparison"></a><a href="#3-val-comparison-note">three value comparison</a></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>0 &lt;=&gt; 1<br>
+<span style="color: maroon">"do"</span> <span style="color: green">cmp</span> <span style="color: maroon">"re"</span></td>
+<td><span style="color: gray"><em>removed from Python 3:</em></span><br>
+<span style="color: purple">cmp</span>(0, 1)<br>
+<span style="color: purple">cmp</span>(<span style="color: maroon">'do'</span>, <span style="color: maroon">'re'</span>)</td>
+<td>0 &lt;=&gt; 1<br>
+<span style="color: maroon">"do"</span> &lt;=&gt; <span style="color: maroon">"re"</span></td>
+</tr>
+<tr>
+<td><a name="arith-op"></a><a href="#arith-op-note">arithmetic operators</a><br>
+<span style="color: gray"><em>addition, subtraction, multiplication, float division, quotient, remainder</em></span></td>
+<td>+ - * / <span style="color: gray"><em>none</em></span> %</td>
+<td>+ - * / <span style="color: gray"><em>none</em></span> %</td>
+<td>+ - * <span style="color: gray"><em>see note</em></span> // %<br>
+<br>
+<span style="color: gray"><em>Python 2 does not have an operator which performs float division on integers. In Python 3 / always performs float division.</em></span></td>
+<td>+ - * x.fdiv(y) / %</td>
+</tr>
+<tr>
+<td><a name="int-div"></a><a href="#int-div-note">integer division</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>(<span style="color: green">int</span>) (13 / 5)</td>
+<td><span style="color: green">int</span> ( 13 / 5 )</td>
+<td>13 // 5</td>
+<td>13 / 5</td>
+</tr>
+<tr>
+<td><a name="divmod"></a><a href="#divmod-note">divmod</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>q, r = <span style="color: purple">divmod</span>(13, 5)</td>
+<td>q, r = 13.divmod(5)</td>
+</tr>
+<tr>
+<td><a name="int-div-zero"></a><a href="#int-div-zero-note">integer division by zero</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>returns</em> FALSE <em>with warning</em></span></td>
+<td><span style="color: gray"><em>error</em></span></td>
+<td><span style="color: gray"><em>raises</em> ZeroDivisionError</span></td>
+<td><span style="color: gray"><em>raises</em> ZeroDivisionError</span></td>
+</tr>
+<tr>
+<td><a name="float-div"></a><a href="#float-div-note">float division</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>13 / 5</td>
+<td>13 / 5</td>
+<td><span style="color: purple">float</span>(13) / 5<br>
+<br>
+<span style="color: gray"># Python 3:</span><br>
+13 / 5</td>
+<td>13.to_f / 5 <span style="color: gray"><em>or</em></span><br>
+13.fdiv(5)</td>
+</tr>
+<tr>
+<td><a name="float-div-zero"></a><a href="#float-div-zero-note">float division by zero</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>returns</em> FALSE <em>with warning</em></span></td>
+<td><span style="color: gray"><em>error</em></span></td>
+<td><span style="color: gray"><em>raises</em> ZeroDivisionError</span></td>
+<td><span style="color: gray"><em>returns</em> -Infinity, NaN, <em>or</em> Infinity</span></td>
+</tr>
+<tr>
+<td><a name="power"></a><a href="#power-note">power</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>pow(2, 32)</td>
+<td>2<span style="white-space: pre-wrap;">**</span>32</td>
+<td>2<span style="white-space: pre-wrap;">**</span>32</td>
+<td>2<span style="white-space: pre-wrap;">**</span>32</td>
+</tr>
+<tr>
+<td><a name="sqrt"></a><a href="#sqrt-note">sqrt</a></td>
+<td>sqrt(2)</td>
+<td><span style="color: green">sqrt</span>(2)</td>
+<td><span style="color: purple">import</span> math<br>
+<br>
+math.sqrt(2)</td>
+<td>include <span style="color: green">Math</span><br>
+<br>
+sqrt(2)</td>
+</tr>
+<tr>
+<td><a name="sqrt-negative-one"></a><a href="#sqrt-negative-one-note">sqrt -1</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>NaN</td>
+<td><span style="color: gray"><em>error unless</em> use Math::Complex <em>in effect</em></span></td>
+<td><span style="color: gray"># raises ValueError:</span><br>
+<span style="color: purple">import</span> math<br>
+math.sqrt(-1)<br>
+<br>
+<span style="color: gray"># returns complex float:</span><br>
+<span style="color: purple">import</span> cmath<br>
+cmath.sqrt(-1)</td>
+<td><span style="color: gray"><em>raises</em> Errno::EDOM</span></td>
+</tr>
+<tr>
+<td><a name="transcendental-func"></a><a href="#transcendental-func-note">transcendental functions</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>exp log sin cos tan asin acos atan atan2</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Math::Trig</span> <span style="color: green">qw</span>(<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>tan asin acos atan);<br>
+<br>
+<span style="color: green">exp log sin cos</span> tan asin acos atan <span style="color: green">atan2</span></td>
+<td><span style="color: purple">from</span> math <span style="color: purple">import</span> exp, log, \<br>
+sin, cos, tan, asin, acos, atan, atan2</td>
+<td>include <span style="color: green">Math</span><br>
+<br>
+exp log sin cos tan asin acos atan atan2</td>
+</tr>
+<tr>
+<td><a name="transcendental-const"></a><a href="#transcendental-const-note">transcendental constants</a><br>
+<span style="color: gray"><em>π and e</em></span></td>
+<td><span style="color: teal">M_PI M_E</span></td>
+<td></td>
+<td>import <span style="color: purple">math</span><br>
+<br>
+math.pi math.e</td>
+<td>include <span style="color: green">Math</span><br>
+<br>
+<span style="color: green">PI E</span></td>
+</tr>
+<tr>
+<td><a name="float-truncation"></a><a href="#float-truncation-note">float truncation</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>(int)$x<br>
+round($<span style="color: peru">x</span>)<br>
+ceil($<span style="color: peru">x</span>)<br>
+floor($<span style="color: peru">x</span>)</td>
+<td><span style="color: gray"># cpan -i Number::Format</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Number::Format</span> <span style="color: maroon">'round'</span>;<br>
+<span style="color: purple">use</span> <span style="color: mediumblue">POSIX</span> <span style="color: green">qw</span>(ceil floor);<br>
+<br>
+<span style="color: green">int</span>($x)<br>
+round($x, 0)<br>
+ceil($x)<br>
+floor($x)</td>
+<td><span style="color: purple">import</span> math<br>
+<br>
+<span style="color: purple">int</span>(x)<br>
+<span style="color: purple">int</span>(<span style="color: purple">round</span>(x))<br>
+math.ceil(x)<br>
+math.floor(x)</td>
+<td>x.to_i<br>
+x.round<br>
+x.ceil<br>
+x.floor</td>
+</tr>
+<tr>
+<td><a name="abs-val"></a><a href="#abs-val-note">absolute value</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>abs($<span style="color: peru">x</span>)</td>
+<td><span style="color: green">abs</span>($x)</td>
+<td><span style="color: purple">abs</span>(x)</td>
+<td>x.abs</td>
+</tr>
+<tr>
+<td><a name="int-overflow"></a><a href="#int-overflow-note">integer overflow</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>converted to float</em></span></td>
+<td><span style="color: gray"><em>converted to float; use</em> Math::BigInt <em>to create arbitrary length integers</em></span></td>
+<td><span style="color: gray"><em>becomes arbitrary length integer of type</em> long</span></td>
+<td><span style="color: gray"><em>becomes arbitrary length integer of type</em> Bignum</span></td>
+</tr>
+<tr>
+<td><a name="float-overflow"></a><a href="#float-overflow-note">float overflow</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>INF</td>
+<td>inf</td>
+<td><span style="color: gray"><em>raises</em> OverflowError</span></td>
+<td><span style="color: green">Infinity</span></td>
+</tr>
+<tr>
+<td><a name="rational-construction"></a><a href="#rational-construction-note">rational construction</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Math::BigRat</span>;<br>
+<br>
+<span style="color: purple">my</span> <span style="color: peru">$x</span> = Math::BigRat-&gt;new(<span style="color: maroon">"22/7"</span>);</td>
+<td><span style="color: purple">from</span> fractions <span style="color: purple">import</span> Fraction<br>
+<br>
+<span style="color: peru">x</span> = Fraction(22,7)</td>
+<td>require <span style="color: maroon">'rational'</span><br>
+<br>
+x = <span style="color: green">Rational</span>(22,7)</td>
+</tr>
+<tr>
+<td><a name="rational-decomposition"></a><a href="#rational-decomposition-note">rational decomposition</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>$x-&gt;numerator();<br>
+$x-&gt;denominator();</td>
+<td>x.numerator<br>
+x.denominator</td>
+<td>x.numerator<br>
+x.denominator</td>
+</tr>
+<tr>
+<td><a name="complex-construction"></a><a href="#complex-constructionnote">complex construction</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Math::Complex</span>;<br>
+<br>
+<span style="color: purple">my</span> <span style="color: peru">$z</span> = 1 + 1.414 * i;</td>
+<td><span style="color: peru">z</span> = 1 + 1.414j</td>
+<td>require <span style="color: maroon">'complex'</span><br>
+<br>
+z = 1 + 1.414.im</td>
+</tr>
+<tr>
+<td><a name="complex-decomposition"></a><a href="#complex-decomposition-note">complex decomposition</a><br>
+<span style="color: gray"><em>real and imaginary component, argument, absolute value, conjugate</em></span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>Re($z);<br>
+Im($z);<br>
+arg($z);<br>
+abs($z);<br>
+~$z;</td>
+<td><span style="color: purple">import</span> cmath<br>
+<br>
+z.real<br>
+z.imag<br>
+cmath.phase(z)<br>
+abs(z)<br>
+z.conjugate()</td>
+<td>z.real<br>
+z.imag<br>
+z.arg<br>
+z.abs<br>
+z.conj</td>
+</tr>
+<tr>
+<td><a name="random-num"></a><a href="#random-num-note">random number</a><br>
+<span style="color: gray"><em>uniform integer, uniform float, normal float</em></span></td>
+<td>rand(0,99)<br>
+lcg_value()<br>
+<span style="color: gray"><em>none</em></span></td>
+<td><span style="color: green">int</span>(<span style="color: green">rand</span>() * 100)<br>
+<span style="color: green">rand</span>()<br>
+<span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">import</span> random<br>
+<br>
+random.randint(0, 99)<br>
+random.random()<br>
+random.gauss(0, 1)</td>
+<td>rand(100)<br>
+rand<br>
+<span style="color: gray"><em>none</em></span></td>
+</tr>
+<tr>
+<td><a name="random-seed"></a><a href="#random-seed-note">random seed</a><br>
+<span style="color: gray"><em>set, get, restore</em></span></td>
+<td>srand(17);<br>
+<br>
+<span style="color: gray"><em>none</em></span></td>
+<td><span style="color: green">srand</span> 17;<br>
+<br>
+<span style="color: purple">my</span> <span style="color: peru">$seed</span> = <span style="color: green">srand</span>;<br>
+<span style="color: green">srand</span>($seed);</td>
+<td><span style="color: purple">import</span> random<br>
+<br>
+random.seed(17)<br>
+<span style="color: peru">seed</span> = random.getstate()<br>
+random.setstate(seed)</td>
+<td>srand(17)<br>
+<br>
+seed = srand<br>
+srand(seed)</td>
+</tr>
+<tr>
+<td><a name="bit-op"></a><a href="#bit-op-note">bit operators</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="white-space: pre-wrap;">&lt;&lt; &gt;&gt; &amp; | ^ ~</span></td>
+<td><span style="white-space: pre-wrap;">&lt;&lt; &gt;&gt; &amp; | ^ ~</span></td>
+<td><span style="white-space: pre-wrap;">&lt;&lt; &gt;&gt; &amp; | ^ ~</span></td>
+<td><span style="white-space: pre-wrap;">&lt;&lt; &gt;&gt; &amp; | ^ ~</span></td>
+</tr>
+<tr>
+<td><a name="binary-octal-hex-literals"></a><a href="#binary-octal-hex-literals-note">binary, octal, and hex literals</a></td>
+<td><span style="color: gray"><em>none</em></span><br>
+052<br>
+0x2a</td>
+<td>0b101010<br>
+052<br>
+0x2a</td>
+<td>0b101010<br>
+052<br>
+0x2a</td>
+<td>0b101010<br>
+052<br>
+0x2a</td>
+</tr>
+<tr>
+<td><a name="base-conversion"></a><a href="#base-conversion-note">base conversion</a></td>
+<td>base_convert(<span style="color: maroon">"42"</span>, 10, 7);<br>
+base_convert(<span style="color: maroon">"60"</span>, 7, 10);</td>
+<td><span style="color: gray"># cpan -i Math::BaseCalc</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Math::BaseCalc</span>;<br>
+<br>
+$c = new Math::BaseCalc(<span style="color: maroon">digits</span>=&gt; [0..6]);<br>
+$c-&gt;to_base(42);<br>
+$c-&gt;from_base(<span style="color: maroon">"60"</span>);</td>
+<td><span style="color: gray"><em>none</em></span><br>
+int(<span style="color: maroon">"60"</span>, 7)</td>
+<td>42.to_s(7)<br>
+<span style="color: maroon">"60"</span>.to_i(7)</td>
+</tr>
+<tr>
+<th colspan="5"><a name="strings"></a><a href="#strings-note">strings</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="str-literal"></a><a href="#str-literal-note">string literal</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: maroon">"don't say \"no\""</span><br>
+<span style="color: maroon">'don\'t say "no"'</span></td>
+<td><span style="color: maroon">"don't say \"no\""</span><br>
+<span style="color: maroon">'don\'t say "no"'</span></td>
+<td><span style="color: maroon">'don\'t say "no"'</span><br>
+<span style="color: maroon">"don't say \"no\""</span><br>
+<span style="color: maroon">"don't "</span> <span style="color: maroon">'say "no"'</span><br>
+<span style="color: maroon">'''don't say "no"'''</span><br>
+<span style="color: maroon">"""don't say "no\""""</span></td>
+<td><span style="color: maroon">"don't say \"no\""</span><br>
+<span style="color: maroon">'don\'t say "no"'</span><br>
+<span style="color: maroon">"don't "</span> <span style="color: maroon">'say "no"'</span></td>
+</tr>
+<tr>
+<td><a name="str-literal-newline"></a><a href="#str-literal-newline-note">newline in literal</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>yes</em></span></td>
+<td><span style="color: gray"><em>yes</em></span></td>
+<td><span style="color: gray"><em>triple quote literals only</em></span></td>
+<td><span style="color: gray"><em>yes</em></span></td>
+</tr>
+<tr>
+<td><a name="char-esc"></a><a href="#char-esc-note">character escapes</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>double quoted:</em></span><br>
+\f \n \r \t \v \x<span style="color: gray"><em>hh</em></span> \$ \" \\ \<span style="color: gray"><em>ooo</em></span><br>
+<br>
+<span style="color: gray"><em>single quoted:</em></span><br>
+\' \\</td>
+<td><span style="color: gray"><em>double quoted:</em></span><br>
+\a \b \c<span style="color: gray"><em>x</em></span> \e \f \n \r \t \x<span style="color: gray"><em>hh</em></span> \x{<span style="color: gray"><em>hhhh</em></span>} \<span style="color: gray"><em>ooo</em></span> <span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: gray"><em>Perl 5.14:</em></span> \o{<span style="color: gray"><em>ooo</em></span>}<br>
+<br>
+<span style="color: gray"><em>single quoted:</em></span><br>
+\' \\</td>
+<td><span style="color: gray"><em>single and double quoted:</em></span><br>
+\<span style="color: gray"><em>newline</em></span> \\ \' \" \a \b \f \n \r \t \v \<span style="color: gray"><em>ooo</em></span> \x<span style="color: gray"><em>hh</em></span><br>
+<br>
+<span style="color: gray"><em>Python 3:</em></span><br>
+\u<span style="color: gray"><em>hhhh</em></span> \U<span style="color: gray"><em>hhhhhhhh</em></span></td>
+<td><span style="color: gray"><em>double quoted:</em></span><br>
+\a \b \c<span style="color: gray"><em>x</em></span> \e \f \n \r \s \t \v \x<span style="color: gray"><em>hh</em></span> \<span style="color: gray"><em>ooo</em></span> <span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: gray"><em>Ruby 1.9:</em></span> \u<span style="color: gray"><em>hhhh</em></span> \u{<span style="color: gray"><em>hhhhh</em></span>}<br>
+<br>
+<span style="color: gray"><em>single quoted:</em></span><br>
+\' \\</td>
+</tr>
+<tr>
+<td><a name="var-interpolation"></a><a href="#var-interpolation-note">variable interpolation</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">count</span> = 3;<br>
+$<span style="color: peru">item</span> = <span style="color: maroon">"ball"</span>;<br>
+<span style="color: purple">echo</span> <span style="color: maroon">"$count ${item}s\n"</span>;</td>
+<td><span style="color: purple">my</span> <span style="color: peru">$count</span> = 3;<br>
+<span style="color: purple">my</span> <span style="color: peru">$item</span> = <span style="color: maroon">"ball"</span>;<br>
+<span style="color: green">print</span> <span style="color: maroon">"$count ${item}s\n"</span>;</td>
+<td><span style="color: peru">count</span> = 3<br>
+<span style="color: peru">item</span> = <span style="color: maroon">'ball'</span><br>
+<span style="color: purple">print</span>(<span style="color: maroon">'{count} {item}s'</span>.format(<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="white-space: pre-wrap;">**</span><span style="color: purple">locals</span>()))</td>
+<td>count = 3<br>
+item = <span style="color: maroon">"ball"</span><br>
+puts <span style="color: maroon">"</span><span style="color: peru">#{count} #{item}</span><span style="color: maroon">s"</span></td>
+</tr>
+<tr>
+<td><a name="custom-delimiters"></a><a href="#custom-delimiters-note">custom delimiters</a></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">my</span> <span style="color: peru">$s1</span> = <span style="color: green">q</span>(lorem ipsum);<br>
+<span style="color: purple">my</span> <span style="color: peru">$s2</span> = <span style="color: green">qq</span>($s1 dolor sit amet);</td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>s1 = %q(lorem ipsum)<br>
+s2 = %Q(#{s1} dolor sit amet)</td>
+</tr>
+<tr>
+<td><a name="sprintf"></a><a href="#sprintf-note">sprintf</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">fmt</span> = <span style="color: maroon">"lorem %s %d %f"</span>;<br>
+sprintf($<span style="color: peru">fmt</span>, <span style="color: maroon">"ipsum"</span>, 13, 3.7);</td>
+<td>my <span style="color: peru">$fmt</span> = <span style="color: maroon">"lorem %s %d %f"</span>;<br>
+<span style="color: green">sprintf</span>($fmt, <span style="color: maroon">"ipsum"</span>, 13, 3.7)</td>
+<td><span style="color: maroon">'lorem %s %d %f'</span> % (<span style="color: maroon">'ipsum'</span>, 13, 3.7)<br>
+<br>
+<span style="color: peru">fmt</span> = <span style="color: maroon">'lorem {0} {1} {2}'</span><br>
+fmt.format(<span style="color: maroon">'ipsum'</span>, 13, 3.7)</td>
+<td><span style="color: maroon">"lorem %s %d %f"</span> % [<span style="color: maroon">"ipsum"</span>,13,3.7]</td>
+</tr>
+<tr>
+<td><a name="here-doc"></a><a href="#here-doc-note">here document</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">word</span> = <span style="color: maroon">"amet"</span>;<br>
+<br>
+$<span style="color: peru">s</span> = <span style="color: maroon"><span style="white-space: pre-wrap;">&lt;&lt;&lt;</span>EOF<br>
+lorem ipsum<br>
+dolor sit $word<br>
+EOF</span>;</td>
+<td>$word = <span style="color: maroon">"amet"</span>;<br>
+<br>
+$s = <span style="white-space: pre-wrap;">&lt;&lt;</span>EOF;<br>
+<span style="color: maroon">lorem ipsum<br>
+dolor sit $word</span><br>
+EOF</td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>word = <span style="color: maroon">"amet"</span><br>
+<br>
+s = <span style="color: maroon"><span style="white-space: pre-wrap;">&lt;&lt;</span>EOF<br>
+lorem ipsum<br>
+dolor sit</span> <span style="color: peru">#{word}</span><br>
+<span style="color: maroon">EOF</span></td>
+</tr>
+<tr>
+<td><a name="str-concat"></a><a href="#str-concat-note">concatenate</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">s</span> = <span style="color: maroon">"Hello, "</span>;<br>
+$<span style="color: peru">s2</span> = $<span style="color: peru">s</span> . <span style="color: maroon">"World!"</span>;</td>
+<td><span style="color: purple">my</span> <span style="color: peru">$s</span> = <span style="color: maroon">"Hello, "</span>;<br>
+<span style="color: purple">my</span> <span style="color: peru">$s2</span> = $s . <span style="color: maroon">"World!"</span>;</td>
+<td><span style="color: peru">s</span> = <span style="color: maroon">'Hello, '</span><br>
+<span style="color: peru">s2</span> = s + <span style="color: maroon">'World!'</span><br>
+<br>
+<span style="color: gray"><em>juxtaposition can be used to concatenate literals:</em></span><br>
+<span style="color: peru">s2</span> = <span style="color: maroon">'Hello, ' "World!"</span></td>
+<td>s = <span style="color: maroon">"Hello, "</span><br>
+s2 = s + <span style="color: maroon">"World!"</span><br>
+<br>
+<span style="color: gray"><em>juxtaposition can be used to concatenate literals:</em></span><br>
+s2 =<span style="color: maroon">"Hello, " 'World!'</span></td>
+</tr>
+<tr>
+<td><a name="str-replicate"></a><a href="#str-replicate-note">replicate</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">hbar</span> = str_repeat(<span style="color: maroon">"-"</span>, 80);</td>
+<td><span style="color: purple">my</span> <span style="color: peru">$hbar</span> = <span style="color: maroon">"-"</span> <span style="color: green">x</span> 80;</td>
+<td><span style="color: peru">hbar</span> = <span style="color: maroon">'-'</span> * 80</td>
+<td>hbar = <span style="color: maroon">"-"</span> * 80</td>
+</tr>
+<tr>
+<td><a name="split"></a><a href="#split-note">split</a><br>
+<span style="color: gray"><em>simple split,<br>
+split in two,<br>
+keep delimiters,<br>
+split into chars</em></span></td>
+<td>explode(<span style="color: maroon">" "</span>, <span style="color: maroon">"do re mi fa"</span>)<br>
+preg_split(<span style="color: maroon">'/\s+/'</span>, <span style="color: maroon">"do re mi fa"</span>, 2)<br>
+preg_split(<span style="color: maroon">'/(\s+)/'</span>, <span style="color: maroon">"do re mi fa"</span>,<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: teal">NULL</span>, <span style="color: teal">PREG_SPLIT_DELIM_CAPTURE</span>);<br>
+str_split(<span style="color: maroon">"abcd"</span>)</td>
+<td><span style="color: green">split</span>(<span style="color: maroon">/\s+/</span>, <span style="color: maroon">"do re mi fa"</span>)<br>
+<span style="color: green">split</span>(<span style="color: maroon">/\s+/</span>, <span style="color: maroon">"do re mi fa"</span>, 2)<br>
+<span style="color: green">split</span>(<span style="color: maroon">/(\s+)/</span>, <span style="color: maroon">"do re mi fa"</span>);<br>
+<span style="color: green">split</span>(<span style="color: maroon"><span style="white-space: pre-wrap;">//</span></span>, <span style="color: maroon">"abcd"</span>)</td>
+<td><span style="color: maroon">'do re mi fa'</span>.split()<br>
+<span style="color: maroon">'do re mi fa'</span>.split(<span style="color: purple">None</span>, 1)<br>
+re.split(<span style="color: maroon">'(\s+)'</span>, <span style="color: maroon">'do re mi fa'</span>)<br>
+<span style="color: purple">list</span>(<span style="color: maroon">'abcd'</span>)</td>
+<td><span style="color: maroon">"do re mi fa"</span>.split<br>
+<span style="color: maroon">"do re mi fa"</span>.split(<span style="color: maroon">/\s+/</span>, 2)<br>
+<span style="color: maroon">"do re mi fa"</span>.split(<span style="color: maroon">/(\s+)/</span>)<br>
+<span style="color: maroon">"abcd"</span>.split(<span style="color: maroon">""</span>)</td>
+</tr>
+<tr>
+<td><a name="join"></a><a href="#join-note">join</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span> = array(<span style="color: maroon">"do"</span>, <span style="color: maroon">"re"</span>, <span style="color: maroon">"mi"</span>, <span style="color: maroon">"fa"</span>);<br>
+implode(<span style="color: maroon">" "</span>, $<span style="color: peru">a</span>)</td>
+<td><span style="color: green">join</span>(<span style="color: maroon">" "</span>, <span style="color: green">qw</span><span style="color: maroon">(do re mi fa)</span>)</td>
+<td><span style="color: maroon">' '</span>.join([<span style="color: maroon">'do'</span>, <span style="color: maroon">'re'</span>, <span style="color: maroon">'mi'</span>, <span style="color: maroon">'fa'</span>])</td>
+<td>%w(do re mi fa).join(<span style="color: maroon">' '</span>)</td>
+</tr>
+<tr>
+<td><a name="case"></a><a href="#case-note">case manipulation</a></td>
+<td>strtoupper(<span style="color: maroon">"lorem"</span>)<br>
+strtolower(<span style="color: maroon">"LOREM"</span>)<br>
+ucfirst(<span style="color: maroon">"lorem"</span>)</td>
+<td><span style="color: green">uc</span>(<span style="color: maroon">"lorem"</span>)<br>
+<span style="color: green">lc</span>(<span style="color: maroon">"LOREM"</span>)<br>
+<span style="color: green">ucfirst</span>(<span style="color: maroon">"lorem"</span>)</td>
+<td><span style="color: maroon">'lorem'</span>.upper()<br>
+<span style="color: maroon">'LOREM'</span>.lower()<br>
+<span style="color: maroon">'lorem'</span>.capitalize()</td>
+<td><span style="color: maroon">"lorem"</span>.upcase<br>
+<span style="color: maroon">"LOREM"</span>.downcase<br>
+<span style="color: maroon">"lorem"</span>.capitalize</td>
+</tr>
+<tr>
+<td><a name="trim"></a><a href="#trim-note">trim</a><br>
+<span style="color: gray"><em>both sides, left, right</em></span></td>
+<td>trim(<span style="color: maroon">" lorem "</span>)<br>
+ltrim(<span style="color: maroon">" lorem"</span>)<br>
+rtrim(<span style="color: maroon">"lorem "</span>)</td>
+<td><span style="color: gray"># cpan -i Text::Trim</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Text::Trim</span>;<br>
+<br>
+trim <span style="color: maroon">" lorem "</span><br>
+ltrim <span style="color: maroon">" lorem"</span><br>
+rtrim <span style="color: maroon">"lorem "</span></td>
+<td><span style="color: maroon">' lorem '</span>.strip()<br>
+<span style="color: maroon">' lorem'</span>.lstrip()<br>
+<span style="color: maroon">'lorem '</span>.rstrip()</td>
+<td><span style="color: maroon">" lorem "</span>.strip<br>
+<span style="color: maroon">" lorem"</span>.lstrip<br>
+<span style="color: maroon">"lorem "</span>.rstrip</td>
+</tr>
+<tr>
+<td><a name="pad"></a><a href="#pad-note">pad</a><br>
+<span style="color: gray"><em>on right, on left, centered</em></span></td>
+<td>str_pad(<span style="color: maroon">"lorem"</span>, 10)<br>
+str_pad(<span style="color: maroon">"lorem"</span>, 10, <span style="color: maroon">" "</span>, <span style="color: teal">STR_PAD_LEFT</span>)<br>
+str_pad(<span style="color: maroon">"lorem"</span>, 10, <span style="color: maroon">" "</span>, <span style="color: teal">STR_PAD_BOTH</span>)</td>
+<td><span style="color: gray"># cpan -i Text::Trim</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Text::Format</span>;<br>
+<br>
+<span style="color: green">sprintf</span>(<span style="color: maroon">"%-10s"</span>, <span style="color: maroon">"lorem"</span>)<br>
+<span style="color: green">sprintf</span>(<span style="color: maroon">"%10s"</span>, <span style="color: maroon">"lorem"</span>)<br>
+<br>
+$text = Text::Format-&gt;new(<span style="color: maroon">columns</span> =&gt; 10);<br>
+$text-&gt;center(<span style="color: maroon">"lorem"</span>);</td>
+<td><span style="color: maroon">'lorem'</span>.ljust(10)<br>
+<span style="color: maroon">'lorem'</span>.rjust(10)<br>
+<span style="color: maroon">'lorem'</span>.center(10)</td>
+<td><span style="color: maroon">"lorem"</span>.ljust(10)<br>
+<span style="color: maroon">"lorem"</span>.rjust(10)<br>
+<span style="color: maroon">"lorem"</span>.center(10)</td>
+</tr>
+<tr>
+<td><a name="num-str-conversion"></a><a href="#num-str-conversion-note">convert from string, to string</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>7 + <span style="color: maroon">"12"</span><br>
+73.9 + <span style="color: maroon">".037"</span><br>
+<span style="color: maroon">"value: "</span> . 8</td>
+<td>7 + <span style="color: maroon">"12"</span><br>
+73.9 + <span style="color: maroon">".037"</span><br>
+<span style="color: maroon">"value: "</span> . 8</td>
+<td>7 + <span style="color: purple">int</span>(<span style="color: maroon">'12'</span>)<br>
+73.9 + <span style="color: purple">float</span>(<span style="color: maroon">'.037'</span>)<br>
+<span style="color: maroon">'value: '</span> + <span style="color: purple">str</span>(8)</td>
+<td>7 + <span style="color: maroon">"12"</span>.to_i<br>
+73.9 + <span style="color: maroon">".037"</span>.to_f<br>
+<span style="color: maroon">"value: "</span> + 8.to_s</td>
+</tr>
+<tr>
+<td><a name="str-length"></a><a href="#str-length-note">length</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>strlen(<span style="color: maroon">"lorem"</span>)</td>
+<td><span style="color: green">length</span>(<span style="color: maroon">"lorem"</span>)</td>
+<td><span style="color: purple">len</span>(<span style="color: maroon">'lorem'</span>)</td>
+<td><span style="color: maroon">"lorem"</span>.length<br>
+<span style="color: maroon">"lorem"</span>.size</td>
+</tr>
+<tr>
+<td><a name="index-substr"></a><a href="#index-substr-note">index of substring</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>strpos(<span style="color: maroon">"do re re"</span>, <span style="color: maroon">"re"</span>)<br>
+strrpos(<span style="color: maroon">"do re re"</span>, <span style="color: maroon">"re"</span>)<br>
+<span style="color: gray"><em>return</em> FALSE <em>if not found</em></span></td>
+<td><span style="color: green">index</span>(<span style="color: maroon">"lorem ipsum"</span>, <span style="color: maroon">"ipsum"</span>)<br>
+<span style="color: green">rindex</span>(<span style="color: maroon">"do re re"</span>, <span style="color: maroon">"re"</span>)<br>
+<span style="color: gray"><em>return</em> -1 <em>if not found</em></span></td>
+<td><span style="color: maroon">'do re re'</span>.index(<span style="color: maroon">'re'</span>)<br>
+<span style="color: maroon">'do re re'</span>.rindex(<span style="color: maroon">'re'</span>)<br>
+<span style="color: gray"><em>raise</em> ValueError <em>if not found</em></span></td>
+<td><span style="color: maroon">"do re re"</span>.index(<span style="color: maroon">"re"</span>)<br>
+<span style="color: maroon">"do re re"</span>.rindex(<span style="color: maroon">"re"</span>)<br>
+<span style="color: gray"><em>return</em> nil <em>if not found</em></span></td>
+</tr>
+<tr>
+<td><a name="extract-substr"></a><a href="#extract-substr-note">extract substring</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>substr(<span style="color: maroon">"lorem ipsum"</span>, 6, 5)</td>
+<td><span style="color: green">substr</span>(<span style="color: maroon">"lorem ipsum"</span>, 6, 5)</td>
+<td><span style="color: maroon">'lorem ipsum'</span>[6:11]</td>
+<td><span style="color: maroon">"lorem ipsum"</span>[6, 5]</td>
+</tr>
+<tr>
+<td><a name="extract-char"></a><a href="#extract-char-note">extract character</a></td>
+<td><span style="color: gray"><em>syntax error to use index notation directly on string literal:</em></span><br>
+$<span style="color: peru">s</span> = <span style="color: maroon">"lorem ipsum"</span>;<br>
+$<span style="color: peru">s</span>[6];</td>
+<td><span style="color: gray"><em>can't use index notation with strings:</em></span><br>
+<span style="color: green">substr</span>(<span style="color: maroon">"lorem ipsum"</span>, 6, 1)</td>
+<td><span style="color: maroon">'lorem ipsum'</span>[6]</td>
+<td><span style="color: maroon">"lorem ipsum"</span>[6]</td>
+</tr>
+<tr>
+<td><a name="chr-ord"></a><a href="#chr-ord-note">chr and ord</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>chr(65)<br>
+ord(<span style="color: maroon">"A"</span>)</td>
+<td><span style="color: green">chr</span>(65)<br>
+<span style="color: green">ord</span>(<span style="color: maroon">"A"</span>)</td>
+<td><span style="color: purple">chr</span>(65)<br>
+<span style="color: purple">ord</span>(<span style="color: maroon">'A'</span>)</td>
+<td>65.chr<br>
+<span style="color: maroon">"A"</span>[0] <span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: gray"><em>Ruby 1.9:</em></span> <span style="color: maroon">"A"</span>.ord</td>
+</tr>
+<tr>
+<td><a name="char-translation"></a><a href="#char-translation-note">character translation</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">ins</span> = implode(range(<span style="color: maroon">"a"</span>, <span style="color: maroon">"z"</span>));<br>
+$<span style="color: peru">outs</span> = substr($<span style="color: peru">ins</span>, 13, 13) . substr($<span style="color: peru">ins</span>, 0, 13);<br>
+strtr(<span style="color: maroon">"hello"</span>, $<span style="color: peru">ins</span>, $<span style="color: peru">outs</span>)</td>
+<td>$s = <span style="color: maroon">"hello"</span>;<br>
+$s =~ <span style="color: green">tr</span>/a-z/n-za-m/;</td>
+<td><span style="color: purple">from</span> string <span style="color: purple">import</span> lowercase <span style="color: purple">as</span> ins<br>
+<span style="color: purple">from</span> string <span style="color: purple">import</span> maketrans<br>
+<br>
+<span style="color: peru">outs</span> = ins[13:] + ins[:13]<br>
+<span style="color: maroon">'hello'</span>.translate(maketrans(ins,outs))</td>
+<td><span style="color: maroon">"hello"</span>.tr(<span style="color: maroon">"a-z"</span>, <span style="color: maroon">"n-za-m"</span>)</td>
+</tr>
+<tr>
+<th colspan="5"><a name="regexes"></a><a href="#regexes-note">regular expresions</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="regex-literal"></a><a href="#regex-literal-note">literal, custom delimited literal</a></td>
+<td><span style="color: maroon">'/lorem|ipsum/'</span><br>
+<span style="color: maroon">'(/etc/hosts)'</span></td>
+<td><span style="color: maroon">/lorem|ipsum/</span><br>
+<span style="color: green">qr</span>(/etc/hosts)</td>
+<td>re.compile(<span style="color: maroon">'lorem|ipsum'</span>)<br>
+<span style="color: gray"><em>none</em></span></td>
+<td><span style="color: maroon">/lorem|ipsum/<br>
+%r(/etc/hosts)</span></td>
+</tr>
+<tr>
+<td><a name="char-class-abbrev-anchors"></a><a href="#char-class-abbrev-anchors-note">character class abbreviations and anchors</a></td>
+<td><span style="color: gray"><em>char class abbrevs:</em></span><br>
+. \d \D \h \H \s \S \v \V \w \W<br>
+<br>
+<span style="color: gray"><em>anchors:</em></span> ^ $ \A \b \B \z \Z</td>
+<td><span style="color: gray"><em>char class abbrevs:</em></span><br>
+. \d \D \h \H \s \S \v \V \w \W<br>
+<br>
+<span style="color: gray"><em>anchors:</em></span> ^ $ \A \b \B \z \Z</td>
+<td><span style="color: gray"><em>char class abbrevs:</em></span><br>
+. \d \D \s \S \w \W<br>
+<br>
+<span style="color: gray"><em>anchors:</em></span> ^ $ \A \b \B \Z</td>
+<td><span style="color: gray"><em>char class abbrevs:</em></span><br>
+. \d \D \h \H \s \S \w \W<br>
+<br>
+<span style="color: gray"><em>anchors:</em></span> ^ $ \A \b \B \z \Z</td>
+</tr>
+<tr>
+<td><a name="regex-test"></a><a href="#regex-test-note">match test</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>if (preg_match(<span style="color: maroon">'/1999/'</span>, $<span style="color: peru">s</span>)) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>echo <span style="color: maroon">"party!\n"</span>;<br>
+}</td>
+<td><span style="color: purple">if</span> ($s =~ <span style="color: maroon">/1999/</span>) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: green">print</span> <span style="color: maroon">"party!\n"</span>;<br>
+}</td>
+<td><span style="color: purple">if</span> re.search(<span style="color: maroon">'1999'</span>, s):<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">print</span>(<span style="color: maroon">'party!'</span>)</td>
+<td><span style="color: purple">if</span> <span style="color: maroon">/1999/</span>.match(s)<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>puts <span style="color: maroon">"party!"</span><br>
+<span style="color: purple">end</span></td>
+</tr>
+<tr>
+<td><a name="case-insensitive-regex"></a><a href="#case-insensitive-regex-note">case insensitive match test</a></td>
+<td>preg_match(<span style="color: maroon">'/lorem/i'</span>, <span style="color: maroon">"Lorem"</span>)</td>
+<td><span style="color: maroon">"Lorem"</span> =~ <span style="color: maroon">/lorem/</span><span style="color: green">i</span></td>
+<td>re.search(<span style="color: maroon">'lorem'</span>, <span style="color: maroon">'Lorem'</span>, re.I)</td>
+<td><span style="color: maroon">/lorem/</span>i.match(<span style="color: maroon">"Lorem"</span>)</td>
+</tr>
+<tr>
+<td><a name="regex-modifiers"></a><a href="#regex-modifiers-note">modifiers</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>e i m s x</td>
+<td>i m s p x</td>
+<td>re.I re.M re.S re.X</td>
+<td>i o m x</td>
+</tr>
+<tr>
+<td><a name="subst"></a><a href="#subst-note">substitution</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">s</span> = <span style="color: maroon">"do re mi mi mi"</span>;<br>
+$<span style="color: peru">s</span> = preg_replace(<span style="color: maroon">'/mi/'</span>, <span style="color: maroon">"ma"</span>, $<span style="color: peru">s</span>);</td>
+<td><span style="color: purple">my</span> $<span style="color: peru">s</span> = <span style="color: maroon">"do re mi mi mi"</span>;<br>
+$s =~ <span style="color: green">s</span><span style="color: maroon">/mi/ma/</span><span style="color: green">g</span>;</td>
+<td><span style="color: peru">s</span> = <span style="color: maroon">'do re mi mi mi'</span><br>
+<span style="color: peru">s</span> = re.compile(<span style="color: maroon">'mi'</span>).sub(<span style="color: maroon">'ma'</span>, s)</td>
+<td>s = <span style="color: maroon">"do re mi mi mi"</span><br>
+s.gsub!(<span style="color: maroon">/mi/</span>, <span style="color: maroon">"ma"</span>)</td>
+</tr>
+<tr>
+<td><a name="match-prematch-postmatch"></a><a href="#match-prematch-postmatch-note">match, prematch, postmatch</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: purple">if</span> ($s =~ <span style="color: maroon">/\d{4}/</span><span style="color: green">p</span>) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>$match = ${^MATCH};<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>$prematch = ${^PREMATCH};<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>$postmatch = ${^POSTMATCH};<br>
+}</td>
+<td><span style="color: peru">m</span> = re.search(<span style="color: maroon">'\d{4}'</span>, s)<br>
+<span style="color: purple">if</span> m:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>match = m.group()<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>prematch = s[0:m.start(0)]<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>postmatch = s[m.end(0):<span style="color: purple">len</span>(s)]</td>
+<td>m = <span style="color: maroon">/\d{4}/</span>.match(s)<br>
+<span style="color: purple">if</span> m<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>match = m[0]<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>prematch = m.pre_match<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>postmatch = m.post_match<br>
+<span style="color: purple">end</span></td>
+</tr>
+<tr>
+<td><a name="group-capture"></a><a href="#group-capture-note">group capture</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">s</span> = <span style="color: maroon">"2010-06-03"</span>;<br>
+$<span style="color: peru">rx</span> = <span style="color: maroon">'/(\d{4})-(\d{2})-(\d{2})/'</span>;<br>
+preg_match($<span style="color: peru">rx</span>, $<span style="color: peru">s</span>, $<span style="color: peru">m</span>);<br>
+list($_, $<span style="color: peru">yr</span>, $<span style="color: peru">mo</span>, $<span style="color: peru">dy</span>) = $<span style="color: peru">m</span>;</td>
+<td>$rx = <span style="color: green">qr</span><span style="color: maroon">/(\d{4})-(\d{2})-(\d{2})/</span>;<br>
+<span style="color: maroon">"2010-06-03"</span> =~ $rx;<br>
+($yr, $mo, $dy) = ($1, $2, $3);</td>
+<td><span style="color: peru">rx</span> = <span style="color: maroon">'(\d{4})-(\d{2})-(\d{2})'</span><br>
+<span style="color: peru">m</span> = re.search(rx, <span style="color: maroon">'2010-06-03'</span>)<br>
+<span style="color: peru">yr</span>, <span style="color: peru">mo</span>, <span style="color: peru">dy</span> = m.groups()</td>
+<td>rx = <span style="color: maroon">/(\d{4})-(\d{2})-(\d{2})/</span><br>
+m = rx.match(<span style="color: maroon">"2010-06-03"</span>)<br>
+yr, mo, dy = m[1..3]</td>
+</tr>
+<tr>
+<td><a name="named-grouped-capture"></a><a href="#named-group-capture-note">named group capture</a></td>
+<td></td>
+<td></td>
+<td>rx = '^(?P&lt;file&gt;.+)\.(?P&lt;suffix&gt;.+)$'<br>
+m = re.search(rx, 'foo.txt')<br>
+m.groupdict()['file']<br>
+m.groupdict()['suffix']</td>
+<td></td>
+</tr>
+<tr>
+<td><a name="scan"></a><a href="#scan-note">scan</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">s</span> = <span style="color: maroon">"dolor sit amet"</span>;<br>
+preg_match_all(<span style="color: maroon">'/\w+/'</span>, $<span style="color: peru">s</span>, $<span style="color: peru">m</span>);<br>
+$<span style="color: peru">a</span> = $<span style="color: peru">m</span>[0];</td>
+<td><span style="color: purple">my</span> $<span style="color: peru">s</span> = <span style="color: maroon">"dolor sit amet"</span>;<br>
+<span style="color: teal">@a</span> = $s =~ <span style="color: green">m</span><span style="color: maroon">/\w+/</span><span style="color: green">g</span>;</td>
+<td><span style="color: peru">s</span> = <span style="color: maroon">'dolor sit amet'</span><br>
+<span style="color: peru">a</span> = re.findall(<span style="color: maroon">'\w+'</span>, s)</td>
+<td>a = <span style="color: maroon">"dolor sit amet"</span>.scan(<span style="color: maroon">/\w+/</span>)</td>
+</tr>
+<tr>
+<td><a name="backreference"></a><a href="#backreference-note">backreference in match and substitution</a></td>
+<td>preg_match(<span style="color: maroon">'/(\w+) \1/'</span>, <span style="color: maroon">"do do"</span>)<br>
+<br>
+$<span style="color: peru">s</span> = <span style="color: maroon">"do re"</span>;<br>
+$<span style="color: peru">rx</span> = <span style="color: maroon">'/(\w+) (\w+)/'</span>;<br>
+$<span style="color: peru">s</span> = preg_replace($<span style="color: peru">rx</span>, <span style="color: maroon">'\2 \1'</span>, $<span style="color: peru">s</span>);</td>
+<td><span style="color: maroon">"do do"</span> =~ <span style="color: maroon">/(\w+) \1/</span><br>
+<br>
+<span style="color: purple">my</span> $<span style="color: peru">s</span> = <span style="color: maroon">"do re"</span>;<br>
+$s =~ <span style="color: green">s</span><span style="color: maroon">/(\w+) (\w+)/$2 $1/</span>;</td>
+<td><span style="color: gray"><em>none</em></span><br>
+<br>
+<span style="color: peru">rx</span> = re.compile(<span style="color: maroon">'(\w+) (\w+)'</span>)<br>
+rx.sub(r<span style="color: maroon">'\2 \1'</span>, <span style="color: maroon">'do re'</span>)</td>
+<td><span style="color: maroon">/(\w+) \1/</span>.match(<span style="color: maroon">"do do"</span>)<br>
+<br>
+<span style="color: maroon">"do re"</span>.sub(<span style="color: maroon">/(\w+) (\w+)/</span>, <span style="color: maroon">'\2 \1'</span>)</td>
+</tr>
+<tr>
+<td><a name="recursive-regex"></a><a href="#recursive-regex-note">recursive regex</a></td>
+<td><span style="color: maroon">'/\(([^()]*|($R))\)/'</span></td>
+<td><span style="color: maroon">/\(([^()]*|(?R))\)/</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: gray"><em>Ruby 1.9:</em></span><br>
+<span style="color: maroon">/(?&lt;p&gt;\(([^()]*|\g&lt;p&gt;)*\))/</span></td>
+</tr>
+<tr>
+<th colspan="5"><a name="dates-time"></a><a href="#dates-time-note">dates and time</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="date-time-type"></a><a href="#date-time-type-note">date/time type</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: green">DateTime</span></td>
+<td><span style="color: gray">Time::Piece <em>if</em> use Time::Piece <em>in effect, otherwise tm array</em></span></td>
+<td>datetime.datetime</td>
+<td><span style="color: green">Time</span></td>
+</tr>
+<tr>
+<td><a name="current-date-time"></a><a href="#current-date-time-note">current date/time</a></td>
+<td>$<span style="color: peru">t</span> = <span style="color: purple">new</span> <span style="color: green">DateTime</span>(<span style="color: maroon">"now"</span>);<br>
+$<span style="color: peru">utc_tmz</span> = <span style="color: purple">new</span> <span style="color: green">DateTimeZone</span>(<span style="color: maroon">"UTC"</span>);<br>
+$<span style="color: peru">utc</span> = <span style="color: purple">new</span> <span style="color: green">DateTime</span>(<span style="color: maroon">"now"</span>, $<span style="color: peru">utc_tmz</span>);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::Piece</span>;<br>
+<br>
+<span style="color: purple">my</span> $<span style="color: peru">t</span> = <span style="color: green">localtime</span>(<span style="color: green">time</span>);<br>
+<span style="color: purple">my</span> $<span style="color: peru">utc</span> = <span style="color: green">gmtime</span>(<span style="color: green">time</span>);</td>
+<td><span style="color: purple">import</span> datetime<br>
+<br>
+<span style="color: peru">t</span> = datetime.datetime.now()<br>
+<span style="color: peru">utc</span> = datetime.datetime.utcnow()</td>
+<td>t = <span style="color: green">Time</span>.now<br>
+utc = <span style="color: green">Time</span>.now.utc</td>
+</tr>
+<tr>
+<td><a name="unix-epoch"></a><a href="#unix-epoch-note">to unix epoch, from unix epoch</a></td>
+<td>$<span style="color: peru">epoch</span> = $<span style="color: peru">t</span>-&gt;getTimestamp();<br>
+$<span style="color: peru">t2</span> = <span style="color: purple">new</span> <span style="color: green">DateTime</span>();<br>
+$<span style="color: peru">t2</span>-&gt;setTimestamp(1304442000);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::Local</span>;<br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Time::Piece</span>;<br>
+<br>
+<span style="color: purple">my</span> $<span style="color: peru">epoch</span> = timelocal($t);<br>
+<span style="color: purple">my</span> $<span style="color: peru">t2</span> = <span style="color: green">localtime</span>(1304442000);</td>
+<td><span style="color: purple">from</span> datetime <span style="color: purple">import</span> datetime <span style="color: purple">as</span> dt<br>
+<br>
+<span style="color: peru">epoch</span> = <span style="color: purple">int</span>(t.strftime(<span style="color: maroon">"%s"</span>))<br>
+<span style="color: peru">t2</span> = dt.fromtimestamp(1304442000)</td>
+<td>epoch = t.to_i<br>
+t2 = <span style="color: green">Time</span>.at(1304442000)</td>
+</tr>
+<tr>
+<td><a name="current-unix-epoch"></a><a href="#current-unix-epoch-note">current unix epoch</a></td>
+<td>$<span style="color: peru">epoch</span> = time();</td>
+<td>$epoch = <span style="color: green">time</span>;</td>
+<td><span style="color: purple">import</span> datetime<br>
+<br>
+<span style="color: peru">t</span> = datetime.datetime.now()<br>
+<span style="color: peru">epoch</span> = <span style="color: purple">int</span>(t.strftime(<span style="color: maroon">"%s"</span>))</td>
+<td>epoch = <span style="color: green">Time</span>.now.to_i</td>
+</tr>
+<tr>
+<td><a name="strftime"></a><a href="#strftime-note">strftime</a></td>
+<td>strftime(<span style="color: maroon">"%Y-%m-%d %H:%M:%S"</span>, $<span style="color: peru">epoch</span>);<br>
+date(<span style="color: maroon">"Y-m-d H:i:s"</span>, $<span style="color: peru">epoch</span>);<br>
+$<span style="color: peru">t</span>-&gt;format(<span style="color: maroon">"Y-m-d H:i:s"</span>);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::Piece</span>;<br>
+<br>
+$t = <span style="color: green">localtime</span>(<span style="color: green">time</span>);<br>
+$fmt = <span style="color: maroon">"%Y-%m-%d %H:%M:%S"</span>;<br>
+<span style="color: green">print</span> $t-&gt;strftime($fmt);</td>
+<td>t.strftime(<span style="color: maroon">'%Y-%m-%d %H:%M:%S'</span>)</td>
+<td>t.strftime(<span style="color: maroon">"%Y-%m-%d %H:%M:%S"</span>)</td>
+</tr>
+<tr>
+<td><a name="date-time-str"></a><a href="#date-time-str-note">default format example</a></td>
+<td><span style="color: gray"><em>no default string representation</em></span></td>
+<td><span style="color: gray">Tue Aug 23&nbsp;19:35:19&nbsp;2011</span></td>
+<td><span style="color: gray">2011-08-23&nbsp;19:35:59.411135</span></td>
+<td><span style="color: gray">2011-08-23&nbsp;17:44:53 -0700</span></td>
+</tr>
+<tr>
+<td><a name="strptime"></a><a href="#strptime-note">strptime</a></td>
+<td>$<span style="color: peru">fmt</span> = <span style="color: maroon">"Y-m-d H:i:s"</span>;<br>
+$<span style="color: peru">s</span> = <span style="color: maroon">"2011-05-03&nbsp;10:00:00"</span>;<br>
+$<span style="color: peru">t</span> = <span style="color: green">DateTime</span>::createFromFormat($<span style="color: peru">fmt</span>,<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>$<span style="color: peru">s</span>);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::Local</span>;<br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Time::Piece</span>;<br>
+<br>
+$s = <span style="color: maroon">"2011-05-03&nbsp;10:00:00"</span>;<br>
+$fmt = <span style="color: maroon">"%Y-%m-%d %H:%M:%S"</span>;<br>
+$t = Time::Piece-&gt;strptime($s,$fmt);</td>
+<td><span style="color: purple">from</span> datetime <span style="color: purple">import</span> datetime<br>
+<br>
+<span style="color: peru">s</span> = <span style="color: maroon">'2011-05-03&nbsp;10:00:00'</span><br>
+<span style="color: peru">fmt</span> = <span style="color: maroon">'%Y-%m-%d %H:%M:%S'</span><br>
+<span style="color: peru">t</span> = datetime.strptime(s, fmt)</td>
+<td>require <span style="color: maroon">'date'</span><br>
+<br>
+s = <span style="color: maroon">"2011-05-03&nbsp;10:00:00"</span><br>
+fmt = <span style="color: maroon">"%Y-%m-%d %H:%M:%S"</span><br>
+t = <span style="color: green">Date</span>.strptime(s, fmt).to_time</td>
+</tr>
+<tr>
+<td><a name="parse-date"></a><a href="#parse-date-note">parse date w/o format</a></td>
+<td>$<span style="color: peru">epoch</span> = strtotime(<span style="color: maroon">"July 7, 1999"</span>);</td>
+<td><span style="color: gray"># cpan -i Date::Parse</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">Date::Parse</span>;<br>
+<br>
+$epoch = str2time(<span style="color: maroon">"July 7, 1999"</span>);</td>
+<td><span style="color: gray"># pip install python-dateutil</span><br>
+<span style="color: purple">import</span> dateutil.parser<br>
+<br>
+<span style="color: peru">s</span> = <span style="color: maroon">'July 7, 1999'</span><br>
+<span style="color: peru">t</span> = dateutil.parser.parse(s)</td>
+<td>require <span style="color: maroon">'date'</span><br>
+<br>
+s = <span style="color: maroon">"July 7, 1999"</span><br>
+t = <span style="color: green">Date</span>.parse(s).to_time</td>
+</tr>
+<tr>
+<td><a name="date-subtraction"></a><a href="#date-subtraction-note">result of date subtraction</a></td>
+<td><span style="color: gray">DateInterval <em>object if</em> diff <em>method used:</em></span><br>
+$<span style="color: peru">fmt</span> = <span style="color: maroon">"Y-m-d H:i:s"</span>;<br>
+$<span style="color: peru">s</span> = <span style="color: maroon">"2011-05-03&nbsp;10:00:00"</span>;<br>
+$<span style="color: peru">then</span> = <span style="color: green">DateTime</span>::createFromFormat($<span style="color: peru">fmt</span>, $<span style="color: peru">s</span>);<br>
+$<span style="color: peru">now</span> = <span style="color: purple">new</span> <span style="color: green">DateTime</span>(<span style="color: maroon">"now"</span>);<br>
+$<span style="color: peru">interval</span> = $<span style="color: peru">now</span>-&gt;diff($<span style="color: peru">then</span>);</td>
+<td><span style="color: gray">Time::Seconds <em>object if</em> use Time::Piece <em>in effect; not meaningful to subtract tm arrays</em></span></td>
+<td><span style="color: gray">datetime.timedelta <em>object</em></span></td>
+<td><span style="color: gray">Float <em>containing time difference in seconds</em></span></td>
+</tr>
+<tr>
+<td><a name="add-time-duration"></a><a href="#add-time-duration-note">add time duration</a></td>
+<td>$<span style="color: peru">now</span> = <span style="color: purple">new</span> <span style="color: green">DateTime</span>(<span style="color: maroon">"now"</span>);<br>
+$<span style="color: peru">now</span>-&gt;add(<span style="color: purple">new</span> <span style="color: green">DateInterval</span>(<span style="color: maroon">"PT10M3S"</span>);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::Seconds</span>;<br>
+<br>
+$now = <span style="color: green">localtime</span>(<span style="color: green">time</span>);<br>
+$now += 10 * ONE_MINUTE() + 3;</td>
+<td><span style="color: purple">import</span> datetime<br>
+<br>
+<span style="color: peru">delta</span> = datetime.timedelta(<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>minutes=10,<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>seconds=3)<br>
+<span style="color: peru">t</span> = datetime.datetime.now() + delta</td>
+<td>require <span style="color: maroon">'date/delta'</span><br>
+<br>
+s = <span style="color: maroon">"10 min, 3&nbsp;s"</span><br>
+delta = <span style="color: green">Date</span>::<span style="color: green">Delta</span>.parse(s).in_secs<br>
+t = <span style="color: green">Time</span>.now + delta</td>
+</tr>
+<tr>
+<td><a name="local-tmz"></a><a href="#local-tmz-note">local timezone</a></td>
+<td><span style="color: gray"><em>DateTime objects can be instantiated without specifying the timezone if a default is set:</em></span><br>
+$<span style="color: peru">s</span> = <span style="color: maroon">"America/Los_Angeles"</span>;<br>
+date_default_timezone_set($<span style="color: peru">s</span>);</td>
+<td><span style="color: gray">Time::Piece <em>has local timezone if created with</em> localtime <em>and UTC timezone if created with</em> gmtime; <em>tm arrays have no timezone or offset info</em></span></td>
+<td><span style="color: gray"><em>a</em> datetime <em>object has no timezone information unless a</em> tzinfo <em>object is provided when it is created</em></span></td>
+<td><span style="color: gray"><em>if no timezone is specified the local timezone is used</em></span></td>
+</tr>
+<tr>
+<td><a name="arbitrary-tmz"></a><a href="#arbitrary-tmz-note">arbitrary timezone</a></td>
+<td></td>
+<td></td>
+<td># pip install pytz<br>
+import pytz<br>
+import datetime<br>
+<br>
+tmz = pytz.timezone('Asia/Tokyo')<br>
+utc = datetime.datetime.utcnow()<br>
+utc_dt = datetime.datetime(<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>*utc.timetuple()[0:5],<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>tzinfo=pytz.utc)<br>
+jp_dt = utc_dt.astimezone(tmz)</td>
+<td># gem install tzinfo<br>
+require 'tzinfo'<br>
+<br>
+tmz = TZInfo::Timezone.get("Asia/Tokyo")<br>
+jp_time = tmz.utc_to_local(Time.now.utc)</td>
+</tr>
+<tr>
+<td><a name="timezone-offset"></a><a href="#timezone-offset-note">timezone name; offset from UTC; is daylight savings?</a></td>
+<td>$<span style="color: peru">tmz</span> = date_timezone_get($<span style="color: peru">t</span>);<br>
+timezone_name_get($<span style="color: peru">tmz</span>);<br>
+date_offset_get($<span style="color: peru">t</span>) / 3600;<br>
+$<span style="color: peru">t</span>-&gt;format(<span style="color: maroon">"I"</span>);</td>
+<td><span style="color: gray"># cpan -i DateTime</span><br>
+<span style="color: purple">use</span> <span style="color: mediumblue">DateTime</span>;<br>
+<span style="color: purple">use</span> <span style="color: mediumblue">DateTime::TimeZone</span>;<br>
+<br>
+$dt = DateTime-&gt;now();<br>
+$tz = DateTime::TimeZone-&gt;new(<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: maroon">name</span>=&gt;<span style="color: maroon">"local"</span>);<br>
+<br>
+$tz-&gt;name;<br>
+$tz-&gt;offset_for_datetime($dt) /<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>3600;<br>
+$tz-&gt;is_dst_for_datetime($dt);</td>
+<td><span style="color: purple">import</span> time<br>
+<br>
+<span style="color: peru">tm</span> = time.localtime()<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><br>
+time.tzname[tm.tm_isdst]<br>
+(time.timezone / -3600) + tm.tm_isdst<br>
+tm.tm_isdst</td>
+<td>t.zone<br>
+t.utc_offset / 3600<br>
+t.dst?</td>
+</tr>
+<tr>
+<td><a name="microseconds"></a><a href="#microseconds-note">microseconds</a></td>
+<td>list($<span style="color: peru">frac</span>, $<span style="color: peru">sec</span>) = explode(<span style="color: maroon">" "</span>,<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>microtime());<br>
+$<span style="color: peru">usec</span> = $<span style="color: peru">frac</span> * 1000 * 1000;</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Time::HiRes</span> <span style="color: green">qw</span>(gettimeofday);<br>
+<br>
+($sec, $usec) = gettimeofday;</td>
+<td>t.microsecond</td>
+<td>t.usec</td>
+</tr>
+<tr>
+<td><a name="sleep"></a><a href="#sleep-note">sleep</a></td>
+<td><span style="color: gray"><em>a float argument will be truncated to an integer:</em></span><br>
+sleep(1);</td>
+<td><span style="color: gray"><em>a float argument will be truncated to an integer:</em></span><br>
+<span style="color: green">sleep</span> 1;</td>
+<td><span style="color: purple">import</span> time<br>
+<br>
+time.sleep(0.5)</td>
+<td>sleep(0.5)</td>
+</tr>
+<tr>
+<td><a name="timeout"></a><a href="#timeout-note">timeout</a></td>
+<td><span style="color: gray"><em>use</em> set_time_limit <em>to limit execution time of the entire script; use</em> stream_set_timeout <em>to limit time spent reading from a stream opened with</em> fopen <em>or</em> fsockopen</span></td>
+<td><span style="color: purple">eval</span> {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: teal">$SIG</span>{<span style="color: maroon">ALRM</span>}= <span style="color: purple">sub</span> {<span style="color: purple">die</span> <span style="color: maroon">"timeout!"</span>;};<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: green">alarm</span> 5;<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: green">sleep</span> 10;<br>
+};<br>
+<span style="color: green">alarm</span> 0;</td>
+<td><span style="color: purple">import</span> signal, time<br>
+<br>
+<span style="color: purple">class</span> <span style="color: green">Timeout</span>(<span style="color: green">Exception</span>): <span style="color: purple">pass</span><br>
+<br>
+<span style="color: purple">def</span> <span style="color: mediumblue">timeout_handler</span>(signo, fm):<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">raise</span> Timeout()<br>
+<br>
+signal.signal(signal.SIGALRM,<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>timeout_handler)<br>
+<br>
+<span style="color: purple">try</span>:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>signal.alarm(5)<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>time.sleep(10)<br>
+<span style="color: purple">except</span> Timeout:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">pass</span><br>
+signal.alarm(0)</td>
+<td>require <span style="color: maroon">'timeout'</span><br>
+<br>
+<span style="color: purple">begin</span><br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: green">Timeout</span>.timeout(5) <span style="color: purple">do</span><br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>sleep(10)<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">end</span><br>
+<span style="color: purple">rescue</span> <span style="color: green">Timeout</span>::<span style="color: green">Error</span><br>
+<span style="color: purple">end</span></td>
+</tr>
+<tr>
+<th colspan="5"><a name="arrays"></a><a href="#arrays-note">arrays</a></th>
+</tr>
+<tr>
+<th></th>
+<th>php</th>
+<th>perl</th>
+<th>python</th>
+<th>ruby</th>
+</tr>
+<tr>
+<td><a name="array-literal"></a><a href="#array-literal-note">literal</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span> = array(1, 2, 3, 4);</td>
+<td><span style="color: teal">@a</span> = (1, 2, 3, 4);</td>
+<td><span style="color: peru">a</span> = [1, 2, 3, 4]</td>
+<td>a = [1, 2, 3, 4]</td>
+</tr>
+<tr>
+<td><a name="quote-words"></a><a href="#quote-words-note">quote words</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td><span style="color: teal">@a</span> = <span style="color: green">qw</span>(do re mi);</td>
+<td><span style="color: gray"><em>none</em></span></td>
+<td>a = %w(do re mi)</td>
+</tr>
+<tr>
+<td><a name="array-size"></a><a href="#array-size-note">size</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>count($<span style="color: peru">a</span>)</td>
+<td><span style="color: teal">$#a</span> + 1 <span style="color: gray"><em>or</em></span><br>
+<span style="color: green">scalar</span>(<span style="color: teal">@a</span>)</td>
+<td><span style="color: purple">len</span>(a)</td>
+<td>a.size<br>
+a.length <span style="color: gray"># same as size</span></td>
+</tr>
+<tr>
+<td><a name="array-empty"></a><a href="#array-empty-note">empty test</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>!$<span style="color: peru">a</span></td>
+<td>!<span style="color: teal">@a</span></td>
+<td><span style="color: purple">not</span> a</td>
+<td><span style="color: gray">NoMethodError <em>if</em> a <em>is</em> nil:</span><br>
+a.empty?</td>
+</tr>
+<tr>
+<td><a name="array-lookup"></a><a href="#array-lookup-note">lookup</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span>[0]</td>
+<td><span style="color: teal">$a</span>[0]</td>
+<td>a[0]</td>
+<td>a[0]</td>
+</tr>
+<tr>
+<td><a name="array-update"></a><a href="#array-update-note">update</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span>[0] = <span style="color: maroon">"lorem"</span>;</td>
+<td><span style="color: teal">$a</span>[0] = <span style="color: maroon">"lorem"</span>;</td>
+<td>a[0] = <span style="color: maroon">'lorem'</span></td>
+<td>a[0] = <span style="color: maroon">"lorem"</span></td>
+</tr>
+<tr>
+<td><a name="array-out-of-bounds"></a><a href="#array-out-of-bounds-note">out-of-bounds behavior</a></td>
+<td>$<span style="color: peru">a</span> = array();<br>
+<span style="color: gray"><em>evaluates as</em> NULL:</span><br>
+$<span style="color: peru">a</span>[10];<br>
+<span style="color: gray"><em>increases array size to one:</em></span><br>
+$<span style="color: peru">a</span>[10] = <span style="color: maroon">"lorem"</span>;</td>
+<td><span style="color: teal">@a</span> = ();<br>
+<span style="color: gray"><em>evaluates as</em> undef:</span><br>
+<span style="color: teal">$a</span>[10];<br>
+<span style="color: gray"><em>increases array size to 11:</em></span><br>
+<span style="color: teal">$a</span>[10] = <span style="color: maroon">"lorem"</span>;</td>
+<td><span style="color: peru">a</span> = []<br>
+<span style="color: gray"><em>raises</em> IndexError:</span><br>
+a[10]<br>
+<span style="color: gray"><em>raises</em> IndexError:</span><br>
+a[10] = <span style="color: maroon">'lorem'</span></td>
+<td>a = []<br>
+<span style="color: gray"><em>evaluates as</em> nil:</span><br>
+a[10]<br>
+<span style="color: gray"><em>increases array size to 11:</em></span><br>
+a[10] = <span style="color: maroon">"lorem"</span></td>
+</tr>
+<tr>
+<td><a name="array-element-index"></a><a href="#array-element-index-note">index of array element</a></td>
+<td>$<span style="color: peru">a</span> = array(<span style="color: maroon">"x"</span>, <span style="color: maroon">"y"</span>, <span style="color: maroon">"z"</span>, <span style="color: maroon">"w"</span>);<br>
+$<span style="color: peru">i</span> = array_search(<span style="color: maroon">"y"</span>, $<span style="color: peru">a</span>);</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">List::Util</span> <span style="color: maroon">'first'</span>;<br>
+<br>
+<span style="color: teal">@a</span> = <span style="color: green">qw</span>(x y z w);<br>
+$i = first {<span style="color: teal">$a</span>[$_] <span style="color: green">eq</span> <span style="color: maroon">"y"</span>} (0..<span style="color: teal">$#a</span>);</td>
+<td><span style="color: peru">a</span> = [<span style="color: maroon">'x'</span>, <span style="color: maroon">'y'</span>, <span style="color: maroon">'z'</span>, <span style="color: maroon">'w'</span>]<br>
+<span style="color: peru">i</span> = a.index(<span style="color: maroon">'y'</span>)</td>
+<td>a = %w(x y z w)<br>
+i = a.index(<span style="color: maroon">"y"</span>)</td>
+</tr>
+<tr>
+<td><a name="array-slice"></a><a href="#array-slice-note">slice by endpoints, by length</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: gray"><em>select 3rd and 4th elements:</em></span><br>
+<span style="color: gray"><em>none</em></span><br>
+array_slice($<span style="color: peru">a</span>, 2, 2)</td>
+<td><span style="color: gray"><em>select 3rd and 4th elements:</em></span><br>
+<span style="color: teal">@a</span>[2..3]<br>
+<span style="color: green">splice</span>(<span style="color: teal">@a</span>, 2, 2)</td>
+<td><span style="color: gray"><em>select 3rd and 4th elements:</em></span><br>
+a[2:4]<br>
+a[<span style="white-space: pre-wrap;">2:2</span> + 2]</td>
+<td><span style="color: gray"><em>select 3rd and 4th elements:</em></span><br>
+a[2..3]<br>
+a[2, 2]</td>
+</tr>
+<tr>
+<td><a name="array-slice-to-end"></a><a href="#array-slice-to-end-note">slice to end</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>array_slice($<span style="color: peru">a</span>, 1)</td>
+<td><span style="color: teal">@a</span>[1..<span style="color: teal">$#a</span>]</td>
+<td>a[1:]</td>
+<td>a[1..-1]</td>
+</tr>
+<tr>
+<td><a name="array-back"></a><a href="#array-back-note">manipulate back</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span> = array(6,7,8);<br>
+array_push($<span style="color: peru">a</span>, 9);<br>
+$<span style="color: peru">a</span>[] = 9; <span style="color: gray"># same as array_push</span><br>
+array_pop($<span style="color: peru">a</span>);</td>
+<td><span style="color: teal">@a</span> = (6,7,8);<br>
+<span style="color: green">push</span> <span style="color: teal">@a</span>, 9;<br>
+<span style="color: green">pop</span> <span style="color: teal">@a</span>;</td>
+<td><span style="color: peru">a</span> = [6,7,8]<br>
+a.append(9)<br>
+a.pop()</td>
+<td>a = [6,7,8]<br>
+a.push(9)<br>
+a <span style="white-space: pre-wrap;">&lt;&lt;</span> 9 <span style="color: gray"># same as push</span><br>
+a.pop</td>
+</tr>
+<tr>
+<td><a name="array-front"></a><a href="#array-front-note">manipulate front</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td>$<span style="color: peru">a</span> = array(6,7,8);<br>
+array_unshift($<span style="color: peru">a</span>, 5);<br>
+array_shift($<span style="color: peru">a</span>);</td>
+<td><span style="color: teal">@a</span> = (6,7,8);<br>
+<span style="color: green">unshift</span> <span style="color: teal">@a</span>, 5;<br>
+<span style="color: green">shift</span> <span style="color: teal">@a</span>;</td>
+<td><span style="color: peru">a</span> = [6,7,8]<br>
+a.insert(0,5)<br>
+a.pop(0)</td>
+<td>a = [6,7,8]<br>
+a.unshift(5)<br>
+a.shift</td>
+</tr>
+<tr>
+<td><a name="array-concatenation"></a><a href="#array-concatenation-note">concatenate</a></td>
+<td>$<span style="color: peru">a</span> = array(1,2,3);<br>
+$<span style="color: peru">a2</span> = array_merge($<span style="color: peru">a</span>,array(4,5,6));<br>
+$<span style="color: peru">a</span> = array_merge($<span style="color: peru">a</span>,array(4,5,6));</td>
+<td><span style="color: teal">@a</span> = (1,2,3);<br>
+<span style="color: teal">@a2</span> = (<span style="color: teal">@a</span>,(4,5,6));<br>
+<span style="color: green">push</span> <span style="color: teal">@a</span>, (4,5,6);</td>
+<td><span style="color: peru">a</span> = [1,2,3]<br>
+<span style="color: peru">a2</span> = a + [4,5,6]<br>
+a.extend([4,5,6])</td>
+<td>a = [1,2,3]<br>
+a2 = a + [4,5,6]<br>
+a.concat([4,5,6])</td>
+</tr>
+<tr>
+<td><a name="array-replication"></a><a href="#array-replication-note">replicate</a></td>
+<td></td>
+<td><span style="color: teal">@a</span> = (<span style="color: green">undef</span>) <span style="color: green">x</span> 10;</td>
+<td>a = [<span style="color: purple">None</span>] * 10<br>
+a = [<span style="color: purple">None for</span> i <span style="color: purple">in range</span>(0, 10)]</td>
+<td>a = [<span style="color: peru">nil</span>] * 10<br>
+a = <span style="color: green">Array</span>.new(10, <span style="color: peru">nil</span>)</td>
+</tr>
+<tr>
+<td><a name="array-copy"></a><a href="#array-copy-note">address copy, shallow copy, deep copy</a></td>
+<td>$<span style="color: peru">a</span> = array(1,2,array(3,4));<br>
+$<span style="color: peru">a2</span> =&amp; $<span style="color: peru">a</span>;<br>
+<span style="color: gray"><em>none</em></span><br>
+$<span style="color: peru">a4</span> = $<span style="color: peru">a</span>;</td>
+<td><span style="color: purple">use</span> <span style="color: mediumblue">Storable</span> <span style="color: maroon">'dclone'</span><br>
+<br>
+<span style="color: purple">my</span> <span style="color: teal">@a</span> = (1,2,[3,4]);<br>
+<span style="color: purple">my</span> <span style="color: peru">$a2</span> = \<span style="color: teal">@a</span>;<br>
+<span style="color: purple">my</span> <span style="color: teal">@a3</span> = <span style="color: teal">@a</span>;<br>
+<span style="color: purple">my</span> <span style="color: teal">@a4</span> = @{dclone(\<span style="color: teal">@a</span>)};</td>
+<td><span style="color: purple">import</span> copy<br>
+<br>
+<span style="color: peru">a</span> = [1,2,[3,4]]<br>
+<span style="color: peru">a2</span> = a<br>
+<span style="color: peru">a3</span> = <span style="color: purple">list</span>(a)<br>
+<span style="color: peru">a4</span> = copy.deepcopy(a)</td>
+<td>a = [1,2,[3,4]]<br>
+a2 = a<br>
+a3 = a.dup<br>
+a4 = <span style="color: green">Marshal</span>.load(<span style="color: green">Marshal</span>.dump(a))</td>
+</tr>
+<tr>
+<td><a name="array-arguments"></a><a href="#array-arguments-note">arrays as function arguments</a></td>
+<td><span style="color: gray"><em>parameter contains deep copy</em></span></td>
+<td><span style="color: gray"><em>each element passed as separate argument; use reference to pass array as single argument</em></span></td>
+<td><span style="color: gray"><em>parameter contains address copy</em></span></td>
+<td><span style="color: gray"><em>parameter contains address copy</em></span></td>
+</tr>
+<tr>
+<td><a name="array-iteration"></a><a href="#array-iteration-note">iteration</a><br>
+<span style="white-space: pre-wrap;">&nbsp;</span></td>
+<td><span style="color: purple">foreach</span> (array(1,2,3) <span style="color: purple">as</span> $<span style="color: peru">i</span>) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">echo</span> <span style="color: maroon">"$i\n"</span>;<br>
+}</td>
+<td><span style="color: purple">for</span> <span style="color: peru">$i</span> (1, 2, 3) { <span style="color: green">print</span> <span style="color: maroon">"$i\n"</span> }</td>
+<td><span style="color: purple">for</span> i <span style="color: purple">in</span> [1,2,3]:<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">print</span>(i)</td>
+<td>[1,2,3].each { |i| puts i }</td>
+</tr>
+<tr>
+<td><a name="indexed-array-iteration"></a><a href="#indexed-array-iteration-note">indexed iteration</a></td>
+<td>$<span style="color: peru">a</span> = array(<span style="color: maroon">"do"</span>, <span style="color: maroon">"re"</span>, <span style="color: maroon">"mi"</span> <span style="color: maroon">"fa"</span>);<br>
+<span style="color: purple">foreach</span> ($<span style="color: peru">a</span> as $<span style="color: peru">i</span> =&gt; $<span style="color: peru">s</span>) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">echo</span> <span style="color: maroon">"$s at index $i\n"</span>;<br>
+}</td>
+<td><span style="color: gray"><em>none; use range iteration from</em> 0 <em>to</em> $#a <em>and use index to look up value in the loop body</em></span></td>
+<td><span style="color: peru">a</span> = [<span style="color: maroon">'do'</span>, <span style="color: maroon">'re'</span>, <span style="color: maroon">'mi'</span>, <span style="color: maroon">'fa'</span>]<br>
+<span style="color: purple">for</span> i, s <span style="color: purple">in</span> enumerate(a):<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: purple">print</span>(<span style="color: maroon">'%s at index %d'</span> % (s, i))</td>
+<td>a = %w(do re mi fa)<br>
+a.each_with_index do |s,i|<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span>puts <span style="color: maroon">"</span><span style="color: peru">#{s}</span> <span style="color: maroon">at index</span> <span style="color: peru">#{i}</span><span style="color: maroon">"</span><br>
+end</td>
+</tr>
+<tr>
+<td><a name="range-iteration"></a><a href="#range-iteration-note">iterate over range</a></td>
+<td><span style="color: gray"><em>not space efficient; use C-style for loop</em></span></td>
+<td><span style="color: purple">for</span> <span style="color: peru">$i</span> (1..1_000_000) {<br>
+<span style="white-space: pre-wrap;">&nbsp;&nbsp;</span><span style="color: gray"><em>code</em></span><br>
+}</td>
+<td><span style="color: gray">range <em>replaces</em> xrange <em>in Python 3:</em></span><br>