2008-09-01ãã1ã¶æéã®è¨äºä¸è¦§
Perl ⺠é¢æ° ⺠here reverseé¢æ°ã使ç¨ããã¨ãé åã¾ãã¯æååã®é åºãéé ã«ãããã¨ãã§ãã¾ããreverseé¢æ°ã¯é åã«å¯¾ãã¦ä½¿ç¨ããã¨é åã®é åºãå転ããã¾ãããæååã«å¯¾ãã¦ä½¿ç¨ããã¨æååãå転ããã¾ãã my $reversed = reverse $str; my @reâ¦
Perl ⺠é¢æ° ⺠here ordé¢æ°ã使ç¨ããã°ãASCIIã³ã¼ãã®æåãå é¨è¡¨ç¾ã§ããæ°å¤ã«å¤æãããã¨ãã§ãã¾ããããã¯chré¢æ°ã¨å対ã®å¤æã§ãã my $ascii_code = ord $char; ordé¢æ°ã®ãµã³ãã« ordé¢æ°ã使ã£ã¦ãASCIIã³ã¼ãã®æåãå é¨è¡¨ç¾ã§ããæ°å¤ã«å¤â¦
Perl ⺠é¢æ° ⺠here chré¢æ°ã使ç¨ããã¨æ°å¤ãASCII(ã¢ã¹ãã¼)ã³ã¼ãã«å¯¾å¿ããæåã«å¤æãããã¨ãã§ãã¾ãã第ï¼å¼æ°ã«ASCIIã³ã¼ããæå®ããã¨ããã«å¯¾å¿ããæåãæ»ãå¤ã§è¿ãã¾ããããã¯ordé¢æ°ã®éã®æ¼ç®ã§ãã my $char = chr $ascii_code; chré¢â¦
Perl ⺠é¢æ° ⺠here crypté¢æ°ã使ãã¨ããã¹ã¯ã¼ãããã¤ã¸ã§ã¹ãã«ãã¦ä¿åãã¦ãããã¨ãã§ãã¾ãããã¹ã¯ã¼ããå¹³æã§ä¿åãã¦ããã¨è¦ããã¦ãã¾ãã¾ãã第ä¸å¼æ°ã¯ãã¹ã¯ã¼ãã§ãã第äºå¼æ°ã¯ãµã«ãã¨ããä»»æã®æååã§ããã¤ã¸ã§ã¹ãã解èªããã«ãâ¦
Perl ⺠é¢æ° ⺠here lengthé¢æ°ã使ç¨ããã¨æååã®é·ããåå¾ãããããã¨ãã§ãã¾ãã $ret = length $str; ãã¨ãã°ãabcdeãã¨ããæååã®é·ãã¯5ã«ãªãã¾ãã # æååã®é·ãã¯5 my $length = length 'abcde'; æ¥æ¬èªã®æååã®é·ããæ£ããåå¾ãã â¦
Perl ⺠ã¢ã¸ã¥ã¼ã« ⺠here Perlã®æ°å¤ã®æå¹æ¡æ°ã¯15ã16æ¡ãããã§ãæ®éã®æ¼ç®ã§ã¯ãã以ä¸å¤§ããªæ°ã®æ¼ç®ãè¡ããã¨ãã§ãã¾ããã大ããªæ¡ã®æ°å¤ãæ±ãããå ´åã¯Math::BigIntãMath::BigFloatã使ç¨ãã¾ãã 大ããªæ´æ°ã®æ¼ç® 大ããªæ´æ°ã®æ¼ç®ãè¡ãã«â¦
Perl ⺠é¢æ° ⺠here ceilé¢æ°ã使ç¨ããã¨ãå°æ°ç¹ãåãä¸ãããã¨ãã§ãã¾ãã use POSIX 'ceil'; $ret = ceil $num; ãµã³ãã« ceilé¢æ°ã使ã£ããµã³ãã«ã§ãã use strict; use warnings; use POSIX 'ceil'; my $num1 = 1.5; my $num2 = -1.5; print "(1)â¦
Perl ⺠é¢æ° ⺠here inté¢æ°ã使ç¨ããã¨ãå°æ°ç¹ãå«ãæ°å¤ã®æ´æ°é¨ãåãåºããã¨ãã§ãã¾ãã $ret = int $num; æ´æ°é¨ã¨ããã®ã¯ãå°æ°ããå°æ°ç¹ä»¥ä¸ã®é¨åãåãé¤ããé¨åã®ãã¨ã§ããåãä¸ããåãä¸ãã¨ã¯ç°ãªãã¾ãããã¨ãã°ã1.5ãã¨ããå°æ°ã®â¦
Perl ⺠æ°å¤ ⺠here åæ¨äºå ¥ãè¡ãã«ã¯ãsprintfé¢æ°ã使ç¨ãã¾ãããã©ã¼ãããæå®ããæå¹æ¡ãæå®ãã¦åæ¨äºå ¥ãããå ´åã¯"%.3g"ã"%.5g"ã®ããã«æå®ããå°æ°ç¹ä»¥ä¸ã®ããæ¡ã§åæ¨äºå ¥ãããå ´åã¯"%.3f"ã"%.5f"ã®ããã«æå®ãã¾ãã # å°æ°ç¹ä»¥ä¸ã®â¦
Perl ⺠æ°å¤ ⺠浮åå°æ°ç¹ã®æ¯è¼ ã³ã³ãã¥ã¼ã¿ã¯å é¨çã«ã¯2é²æ°ã使ã£ã¦æ¼ç®ãã¦ããã®ã§ã2é²æ°ã§è¡¨ç¾ã§ããªãå°æ°ã«ã¤ãã¦ã¯è¨ç®ã®éç¨ã§èª¤å·®ãçã¾ãã¾ãã2é²æ°ã®æ¼ç®ã®éç¨ã§çºçãã誤差ã®å½±é¿ãç¡è¦ããããã«ã¯ãããæå¹æ¡ã§æ°å¤ã丸ãã¦æ¯è¼ããâ¦
Perl ⺠é¢æ° ⺠here logé¢æ°ã使ç¨ããã¨ãèªç¶å¯¾æ°ãæ±ãããã¨ãã§ãã¾ããã¾ãåº(ã¦ã)ã®å¤æãå©ç¨ããã°ãä»»æã®åºã®å¯¾æ°ãè¨ç®ã§ãã¾ãã èªç¶å¯¾æ°ãæ±ãã èªç¶å¯¾æ°ãæ±ããã«ã¯logé¢æ°ã使ç¨ãã¾ããèªç¶å¯¾æ°ã¨ã¯åºããã¤ãã¢æ°eã§ãã対æ°ã®ãã¨ã§â¦
Perl ⺠é¢æ° ⺠here expé¢æ°ã使ç¨ããã¨ãèªç¶å¯¾æ°ã®åº ãã¤ãã¢æ°eãåå¾ãããã¨ãã§ãã¾ãã # e my $exp = exp(1); # eã®3ä¹ my $exp3 = exp(3); ãã¤ãã¢æ°eãåå¾ããã«ã¯expé¢æ°ã«1ã渡ãã¾ããå¼æ°ã¯ãã¹ãä¹ã®æå®ã«ãªã£ã¦ããã®ã§ãnãæå®ããã°â¦
Perl ⺠ã¢ã¸ã¥ã¼ã« ⺠here ä¸è§é¢æ°é¢é£ã®é¢æ°ã¯æ¨æºé¢æ°ã¨ãã¦ã¯ãcosé¢æ°ã¨siné¢æ°ããããã¾ããããæ¨æºã¢ã¸ã¥ã¼ã«ã«Math::Trigã¨ããä¸è§é¢æ°é¢é£ã®ã¢ã¸ã¥ã¼ã«ãããã¾ããç°¡åã«å 容ãç´¹ä»ãã¾ãã ä¸è§é¢æ°ã®éæ° éæ°ã¨ã¯ãåæ¯ã¨ååãå ¥ãæ¿ããæ°â¦
Perl ⺠æ°å¤ ⺠here ä¸è§é¢æ°ãå©ç¨ããããã®é¢æ°ãã¢ã¸ã¥ã¼ã«ãç´¹ä»ãã¾ãã ãµã¤ã³ ãµã¤ã³ãæ±ããã«ã¯ãsiné¢æ°ãè§åº¦ã¯Ï(pié¢æ°)ã使ã£ã¦ã弧度æ³ã§æå®ããã®ãç°¡åã§ãã use Math::Trig 'pi'; sin(pi/2); cos(pi/3); (åè)Math::Trig ã³ãµã¤ã³ ã³ãµâ¦
Perl ⺠æ°å¤ ⺠here 度æ°æ³( 30°,90°ãªã© )ã§è¡¨ãããè§åº¦ããã©ã¸ã¢ã³( Ï/6, Ï/4 ãªã© )ã«å¤æããã«ã¯Math::Trigã¢ã¸ã¥ã¼ã«ã®deg2radé¢æ°ã使ç¨ãã¾ãããã®éãè¡ãã«ã¯ãrad2degé¢æ°ã使ç¨ãã¾ãã use Math::Trig 'pi', 'deg2rad'; # 度æ°æ³ã®è§åº¦ã弧â¦
Perl ⺠æ°å¤ ⺠here åå¨çãåå¾ããã«ã¯Math::Trigã¢ã¸ã¥ã¼ã«ã®pié¢æ°ã使ç¨ãã¾ãã use Math::Trig 'pi'; pi; åå¨çã¨ã¯ãåå¨(L)ã¨ç´å¾(R)æ¯ç( L/R )ã®ãã¨ã§ããåå¨çã¯ç¡çæ°ã§ããæéç¯å²ã®å°æ°ã§è¡¨ç¾ãããã¨ãã§ãã¾ãããpiã§åå¾ããåå¨çâ¦
Perl ⺠é¢æ° ⺠here 絶対å¤ãæ±ããã«ã¯absé¢æ°ã使ãã¾ãã abs $num; 絶対å¤ã¨ããã®ã¯ã符å·ãèæ ®ããªã大ããã®ãã¨ã§ã常ã«æ£ã®å¤ã«ãªãã¾ãã0ããã©ããããé¢ãã¦ãããã表ãæ°ã®ãã¨ã§ããã3ãã®å ´åã¯ã3ãã«ãã-3ãã®å ´åã¯ãã3ãã«ãªãã¾ãâ¦
Perl ⺠æ¼ç®å ⺠here Perlã§ååæ¼ç®ãè¡ãããã®ç®è¡æ¼ç®åã«ã¤ãã¦è§£èª¬ãã¾ãã å ç® è¶³ãç®ãè¡ãã«ã¯å ç®æ¼ç®åã+ãã使ç¨ãã¾ãã # 足ãç® my $add = 1 + 1; æ¸ç® å¼ãç®ãè¡ãã«ã¯æ¸ç®æ¼ç®åã-ãã使ç¨ãã¾ãã # å¼ãç® my $sub = 9 - 1; ä¹ç® æâ¦
Perl ⺠ã¢ã¸ã¥ã¼ã« ⺠here æ¬ä¼¼ä¹±æ°ãçºçãããããã¢ã«ã´ãªãºã ã«ã¡ã«ã»ã³ãã»ãã¤ã¹ã¿æ³ã¨ãããã®ãããã¾ããã¡ã«ã»ã³ãã»ãã¤ã¹ã¿æ³ã«ãã£ã¦æ¬ä¼¼ä¹±æ°ãæ±ããã¢ã¸ã¥ã¼ã«ãMath::Random::MTã¨ããã¢ã¸ã¥ã¼ã«ã§ããCAPNããåå¾ãããã¨ãã§ãã¾ãã useâ¦
Perl ⺠é¢æ° ⺠here srandé¢æ°ã使ç¨ããã¨åç¾æ§ã®ããä¹±æ°ãçæãããã¨ãã§ãã¾ããrandé¢æ°ãå¼ã³åºãåã«é©å½ãªæ°å¤ãsrandé¢æ°ã«ä¸ãã¾ãã # ä¹±æ°çºçã¢ã«ã´ãªãºã ãåæå srand $seed; rand $num; ã³ã³ãã¥ã¼ã¿ã«ãããä¹±æ°ã®çæã¨ã¯ ã³ã³ãã¥ã¼â¦
Perl ⺠é¢æ° ⺠here ä¹±æ°ãçæããã«ã¯randé¢æ°ã使ç¨ãã¾ããå¼æ°ã§æå®ããæ°ããå°ãã0以ä¸ã®æ°å¤ãã©ã³ãã ã§çæããã¾ãã $ret = rand 10; ä¹±æ°ã¨ã¯ã©ã³ãã ãªæ°ã®ãã¨ã§ããã¢ããªã±ã¼ã·ã§ã³ãä½æããã¨ãã¯ãæã«ã©ã³ãã ãªæ°ãã»ããã¨ããããâ¦
Perl ⺠é¢æ° ⺠here ucé¢æ°ã使ç¨ããã¨å°æåãã大æåã¸å¤æãããã¨ãã§ãã¾ããucé¢æ°ã¯å¼æ°ã®ããããã®æåã大æåã«å¤æãã¾ããå¤æã§ããªãæåã®å ´åã¯å¼æ°ã«ä¸ããæåããã®ã¾ã¾è¿ããã¾ãã my $str = uc "aaa"; ãµã³ãã«ããã°ã©ã å°æåãâ¦
Perl ⺠é²æ°å¤æ Perlã§ãé²æ°å¤æããè¡ãæ¹æ³ã解説ãã¾ãã 10é²æ°ãã2é²æ°ã8é²æ°ã16é²æ°ã¸ã®å¤æ 10é²æ°ãã2é²æ°ã8é²æ°ã16é²æ°ã«å¤æãã¦ã¿ã¾ããããsprintfé¢æ°ã§ãã©ã¼ãããæå®ã使ãã¾ãã # 2é²æååã«å¤æ my $bit_str = sprintf("%b", $â¦