ktats****@users*****
ktats****@users*****
2012年 8月 5日 (日) 13:09:34 JST
Index: docs/articles/qntm.org/files/perl/perl.html diff -u docs/articles/qntm.org/files/perl/perl.html:1.1 docs/articles/qntm.org/files/perl/perl.html:1.2 --- docs/articles/qntm.org/files/perl/perl.html:1.1 Sun Aug 5 04:24:08 2012 +++ docs/articles/qntm.org/files/perl/perl.html Sun Aug 5 13:09:34 2012 @@ -2,7 +2,7 @@ <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> - <title>Perl</title> + <title>2æéåã§å¦ã¶Perl</title> <style type="text/css"> body { @@ -104,8 +104,8 @@ <h3>ã¹ã«ã©å¤æ°</h3> -<p>A scalar variable can contain:</p> -<p class=original>ã¹ã«ã©å¤æ°ã¯ä»¥ä¸ã®ãã®ãæ ¼ç´ã§ãã¾ã:</p> +<p class=original>A scalar variable can contain:</p> +<p>ã¹ã«ã©å¤æ°ã¯ä»¥ä¸ã®ãã®ãæ ¼ç´ã§ãã¾ã:</p> <ul class=original> <li><tt>undef</tt> (corresponds to <tt>None</tt> in Python, <tt>null</tt> in PHP)</li> <li>a number (Perl does not distinguish between an integer and a float)</li> @@ -119,7 +119,7 @@ <li>ä»ã®å¤æ°ã¸ã®ãªãã¡ã¬ã³ã¹</li> </ul> -<pre class="perl"> +<pre class="perl original"> my $undef = undef; print $undef; # warning @@ -129,6 +129,15 @@ </pre> <pre class="perl"> +my $undef = undef; +print $undef; # warning + +# implicit undef: +my $undef2; +print $undef2; # ã¾ã£ããåãwarning +</pre> + +<pre class="perl"> my $num = 4040.5; print $num; # "4040.5" </pre> @@ -139,7 +148,7 @@ </pre> <p class=original>(References are coming up shortly.)</p> -<p>(ãªãã¡ã¬ã³ã¹ã¯å¾ã§èª¬æããã®ã§ç°¡åã«)</p> +<p>(ãªãã¡ã¬ã³ã¹ã¯å¾ã§èª¬æãã¾ã)</p> <p class=original>String concatenation using the <tt>.</tt> operator (same as PHP):</p> <p>æååã®é£çµã«ã¯<tt>.</tt>æ¼ç®åã使ãã¾ã(PHPã¨åã):</p> @@ -443,7 +452,7 @@ <p class=original>The same is true whether the fat comma is used or not:</p> <p>ãã¡ããã«ã³ãã使ã£ã¦ãã¦ãããªãã¦ãåããçã§ã:</p> -<pre class="perl"> +<pre class="perl original"> my %hash = ( "beer" => "good", "bananas" => ( @@ -463,8 +472,29 @@ print $hash{"bananas"}{"yellow"}; # error </pre> +<pre class="perl"> +my %hash = ( + "beer" => "good", + "bananas" => ( + "green" => "wait", + "yellow" => "eat", + ), +); + +# ä¸ã®ã³ã¼ãã¯warningãåºã¾ããããã·ã¥ã7ã¤ã®è¦ç´ ã®ãªã¹ãã§å®£è¨ããã¦ããããã§ãã + +print $hash{"beer"}; # "good" +print $hash{"bananas"}; # "green" +print $hash{"wait"}; # "yellow"; +print $hash{"eat"}; # undef, ãã®ãããè¦åãã§ã¾ã + +print $hash{"bananas"}{"green"}; # error +print $hash{"bananas"}{"yellow"}; # error +</pre> + + <p class=original>More on this shortly.</p> -<p>More on this shortly.</p> +<p>詳細ã¯å¾ã»ã©ã</p> <h2>ã³ã³ããã¹ã</h2> @@ -556,15 +586,14 @@ <p>ã§ãã, ã¹ã«ã©å¤æ°ã¯ãé åå¤æ°ãããã·ã¥å¤æ°ãå«ããä»ã®å¤æ°ã¸ã®<i>ãªãã¡ã¬ã³ã¹</i>ãæã¦ã¾ããããããPerlã§ããè¤éãªãã¼ã¿æ§é ãä½ãæ¹æ³ã§ãã</p> <p class=original>A reference is created using a backslash.</p> -<p>ãªãã¡ã¬ã³ã¹ã¯ããã¯ã¹ã©ãã·ã¥ã使ã£ã¦ä½ããã¾ãã/p> +<p>ãªãã¡ã¬ã³ã¹ã¯ããã¯ã¹ã©ãã·ã¥ã使ã£ã¦ä½ããã¾ãã</p> <pre class="perl"> my $colour = "Indigo"; my $scalarRef = \$colour; </pre> <p class=original>Any time you would use the name of a variable, you can instead just put some braces in, and, within the braces, put a <em>reference</em> to a variable instead.</p> -<p>ãã¤ã§ããå¤æ°ã®ååã使ãã¾ãã代ããã«ãã¬ã¼ã¹ãç½®ãã¦ããã¬ã¼ã¹å ã«å¤æ°ã¸ã®<em>ãªãã¡ã¬ã³ã¹</em>ãç½®ãã¾ãã -</p> +<p>ãã¤ã§ããå¤æ°ã®ååã使ãã¾ãã代ããã«ãã¬ã¼ã¹ãç½®ãã¦ããã¬ã¼ã¹å ã«å¤æ°ã¸ã®<em>ãªãã¡ã¬ã³ã¹</em>ãç½®ãã¾ãã</p> <pre class="perl"> print $colour; # "Indigo" print $scalarRef; # e.g. "SCALAR(0x182c180)" @@ -579,7 +608,7 @@ </pre> <p class=original>If your reference is a reference to an array or hash variable, you can get data out of it using braces or using the more popular arrow operator, <tt>-></tt>:</p> -<p>ãªãã¡ã¬ã³ã¹ãé åãããã·ã¥å¤æ°ã®ãªãã¡ã¬ã³ã¹ã®å ´åããã¬ã¼ã¹ãããä¸è¬çãªã¢ãã¼æ¼ç®åã<tt>-></tt>ã使ã£ã¦ãã¼ã¿ãåãåºãã¾ãã:</p> +<p>ãªãã¡ã¬ã³ã¹ãé åãããã·ã¥å¤æ°ã®ãªãã¡ã¬ã³ã¹ã®å ´åããã¬ã¼ã¹ãããä¸è¬çãªã¢ãã¼æ¼ç®åã<tt>-></tt>ã使ã£ã¦ãã¼ã¿ãåãåºãã¾ã:</p> <pre class="perl"> my @colours = ("Red", "Orange", "Yellow", "Green", "Blue"); @@ -929,15 +958,16 @@ } </pre> -<p>Since a hash has no underlying order, the keys may be returned in any order. Use the <tt>sort</tt> built-in function to sort the array of keys alphabetically beforehand:</p> +<p class=original>Since a hash has no underlying order, the keys may be returned in any order. Use the <tt>sort</tt> built-in function to sort the array of keys alphabetically beforehand:</p> +<p>ããã·ã¥ã«ã¯é çªãããã¾ããã®ã§ãkeysã¯ã©ã®ãããªé çªã§ãæ»ãã¾ããçµè¾¼ã®<tt>sort</tt>é¢æ°ã使ã£ã¦ãã¢ã«ãã¡ãããé ã§ãã¼ã®é åãã½ã¼ãã§ãã¾ã:</p> <pre class="perl"> foreach my $key (sort keys %scientists) { print $key, ": ", $scientists{$key}; } </pre> -<p>There is also a special <tt>each</tt> built-in function which retrieves key/value pairs one at a time. Every time <tt>each</tt> is called, it returns an array containing two values, until the end of the array is reached, when a false value is returned. We assign the values of two scalars to the values of the array, simultaneously:</p> -<p class=original>ç¹å¥ãªçµè¾¼é¢æ°<tt>each</tt>ããããããã¯ããã¼/å¤ã®ãã¢ãä¸åº¦ã«ã²ã¨ã¤åãåºãã¾ãã<tt>each</tt>ãå¼ã°ãããã³ã«ãé åã®æå¾ã«è³ãã¾ã§ãå½ã®å¤ãæ»ãã¾ã§ã2ã¤ã®å¤ããã¤é åãè¿ãã¾ããé åã®å¤ã2ã¤ã®ã¹ã«ã©ã«ãåæã«å²ãå½ã¦ã¾ã:</p> +<p class=original>There is also a special <tt>each</tt> built-in function which retrieves key/value pairs one at a time. Every time <tt>each</tt> is called, it returns an array containing two values, until the end of the array is reached, when a false value is returned. We assign the values of two scalars to the values of the array, simultaneously:</p> +<p>ç¹å¥ãªçµè¾¼é¢æ°<tt>each</tt>ããããããã¯ããã¼/å¤ã®ãã¢ãä¸åº¦ã«ã²ã¨ã¤åãåºãã¾ãã<tt>each</tt>ãå¼ã°ãããã³ã«ãé åã®æå¾ã«è³ãã¾ã§ãå½ã®å¤ãæ»ãã¾ã§ã2ã¤ã®å¤ããã¤é åãè¿ãã¾ããé åã®å¤ã2ã¤ã®ã¹ã«ã©ã«ãåæã«å²ãå½ã¦ã¾ã:</p> <pre class="perl"> while( my ($key, $value) = each %scientists ) { @@ -1019,8 +1049,8 @@ print @stack; # "HankGraceEileenDeniseBobAlice" </pre> -<p><tt>pop</tt>, <tt>push</tt>, <tt>shift</tt> and <tt>unshift</tt> are all special cases of <tt>splice</tt>. <tt>splice</tt> removes and returns an array slice, replacing it with a different array slice:</p> -<p class=original><tt>pop</tt>ã<tt>push</tt>ã <tt>shift</tt>ã<tt>unshift</tt> ã¯ãå ¨ã¦ã<tt>splice</tt>ã®ç¹å¥ãªã±ã¼ã¹ã§ãã<tt>splice</tt> ã¯ãé åã®ã¹ã©ã¤ã¹ãåé¤ãã¦ãè¿ãã¾ããå¥ã®é åã¹ã©ã¤ã¹ã§ãããç½®ãæãã¾ã:</p> +<p class=original><tt>pop</tt>, <tt>push</tt>, <tt>shift</tt> and <tt>unshift</tt> are all special cases of <tt>splice</tt>. <tt>splice</tt> removes and returns an array slice, replacing it with a different array slice:</p> +<p><tt>pop</tt>ã<tt>push</tt>ã <tt>shift</tt>ã<tt>unshift</tt> ã¯ãå ¨ã¦ã<tt>splice</tt>ã®ç¹å¥ãªã±ã¼ã¹ã§ãã<tt>splice</tt> ã¯ãé åã®ã¹ã©ã¤ã¹ãåé¤ãã¦ãè¿ãã¾ããå¥ã®é åã¹ã©ã¤ã¹ã§ãããç½®ãæãã¾ã:</p> <pre class="perl"> print splice(@stack, 1, 4, "<<<", ">>>"); # "GraceEileenDeniseBob" print @stack; # "Hank<<<>>>Alice"