第140å ãããã¯ã渡ããã®ã¯Rubyã ããããªã!ãPerlã ã£ã¦æ¸¡ãããã ï¼
YAPCãå§ã¾ãã¾ãããã
å»å¹´ã¯åå ããã®ã§ããï¼è´è¡ã®æ¹ã§ããï¼ãä»å¹´ã¯é常ã«ã¨ã¦ã¤ããªãæ®å¿µãªäºã«åå ã§ãã¾ããã
ã§ãæ°åã ãã§ãã²ããããã®ã§Perlã®ã話ãå°ã
ã
Rubyã«åãã£ããããã¯ã¨ããæ¦å¿µ
Rubyã¯è¨èªèªä½ã«é«éé¢æ°ããããã¯ã¨ããå½¢ã§ãã£ã¦ããã
eachãªã©ã§ä½¿ããã¦ããã®ã¯æåã§ãã
ä¾ï¼
array = [1,3,5,9] array.each{|i| puts i}
eachã«ä¸ãã¦ãã { }ã®é¨åããããã¯ã§ãã
èªåã§ãããã¯ãåãåãé¢æ°ãä½ããããã° yield ã使ãã°ããã§ãããã
ä»åã®ã話ã®å
容ã¯ãPerlã§ããããã¯ã渡ãããã¨ãããã¨ãªã®ã§ã
eachã®æ©è½, yieldã®æ©è½ã¯ç¥ã£ã¦ããããã¨ããåæã§å
ã«ããã¿ããã¨æãã¾ãã
Perlã®ãããã¯ã使ã£ãä¾
ããã§ã¯Rubyã®è©±ã¯ãããããã«ãã¦Perlã®è©±ã«ã¾ããã¾ãããã
ã¾ãPerlã§ãã®é«éé¢æ°ã®ããã«æ¯ãèããããã¯ã使ã£ãçµè¾¼é¢æ°ãè¦ã¦ããããã¨æãã¾ãã
ä»åã¯mapã使ã£ãä¾ãç´¹ä»ãã¾ãã
use Data::Dumper; my @c = 1..5; my @d = map { $_ * 2 } @c; # @cã®åè¦ç´ ã2åããé åãè¿ã print Dumper \@d;
çµæï¼
$VAR1 = [ 2, 4, 6, 8, 10 ];
ã½ã¼ã¹ä¸ã®ã³ã¡ã³ãã«ãæ¸ãã¾ããã åè¦ç´ ã2åããé
åãè¿ãã¦ãã¾ãã
map ããã㯠é
å
ã¨ããæ¸å¼ã§ãã
ãããã¯ãå¼æ°ã«ã¨ãé¢æ°ã®ä½ãæ¹
ãã®ããã«ãããã¯ãå¼æ°ã«ã¨ãé¢æ°ã¯èªåã§ã¤ãããã¨ãã§ãã¾ãã
ãã®ãã¨ã«ãããããããPerlã«ãã¨ããåãã£ã¦ããçµè¾¼é¢æ°ãããã¯ææ³ã®ããã«æ¯ãèããããã¨ãï¼æ¸ããã¨ãï¼å¯è½ã¨ãªãã¾ãã
å®ç¾©ã®ä»æ¹ã¯ç°¡åã以ä¸ã®ããã«ãããã¿ã¤ãã使ãã°ããã ãã§ãã
sub(&){ }
ãã®ããã«Perlã®ãããã¿ã¤ãã§&ãæå®ãããã¨ã§ãããã¯ãåãåããã¨ãã§ãã¾ãã
sub hoge(&){ $code = shift; $code->(); } hoge { print 'Hello World' . "\n" } # ãããã¯ã渡ã
ããã ãã ã¨ãã ããä½ï¼ã¨ããæãã§ãã®ã§ã
å®ç¨çãªä¾ãç´¹ä»ãã¾ãããã
Perlã®5.8ããçµã¿è¾¼ã¾ããList::Utilã«åãã£ãfirstã使ãã¨
use List::Util qw(first); my @c = 1..5; my $d = first { $_ > 3 } @c; #æåã«3ãè¶ ãããã®ãåå¾ print $d . "\n";
ãã®ããã«æåã«3ãè¶ ãããã®ãåå¾ãããã¨ãã§ãã¾ãã
ãããèªä½ãããªãã°ã
sub first(&@){ my $code = shift; for(@_){ return $_ if $code->(); } } my @c = 1..5; my $d = first { $_ > 3 } @c; print $d . "\n";
ãã®ããã«ãªãã¾ãã
å®éããã¼ã¸ã§ã³1.21ã®List::Util::PP.pmã®44è¡ç®ã«ã»ã¨ãã©åãã½ã¼ã¹ãçºè¦ã§ãã¾ããã
try{ }catch{ }æ§æã ã£ã¦ä½ãã
ãã®ãããã¯ã使ãã°ãtry{ }catch{ }æ§æã ã£ã¦ä½ãã¾ãã
ããããã£ãã®ãError.pmã§ããã©ã®ããã«ãã£ã¦ã®ãã¦ããã®ãã¯
ããã°ã©ãã³ã°PerlãVOLUME1ã
- ä½è : ã©ãªã¼ã¦ã©ã¼ã«,ã¸ã§ã³ãªã¼ã¯ã³ã,ãã ã¯ãªã¹ãã£ã³ã»ã³,Larry Wall,Jon Orwant,Tom Christiansen,è¿è¤åéª
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã»ã¸ã£ãã³
- çºå£²æ¥: 2002/09/01
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 8人 ã¯ãªãã¯: 245å
- ãã®ååãå«ãããã° (125件) ãè¦ã
æ¦ç¥ã ãç°¡åã«èª¬æããã¨ã
sub try(&$){ } 㨠sub catch(&){ }
ã使ããå®ã«ãã¾ãå
·åã« tryã®ãããã¯ãå
ã«å¦çãããããã«å®è£
ããã¦ããããã§ãã
DSLã ã£ã¦ä½ãã
ãããã¯ã渡ãããã¨ã«ãã£ã¦æè¿æµè¡ã®DSLã ã£ã¦ä½ãäºãã§ãã¾ãã
ããããã£ã¦ããã®ããWeb::Scraperã§ãã
scraper { }
ã®ãããã¯ã®ä¸ã«ã©ã®ãããªå¦çãè¡ãªã£ã¦ã»ããã®ã示ããã¨ãã§ãã¾ãã
ãããã¯ãåãåããããã«ã§ããã®ã¯ç¬¬1å¼æ°ã ã
æå¾ã«æ³¨æäºé
ã§ãã
ããã¿ã¤ãã«&ãæ¸ãã¦ãããã¯ãããããã¨ãã§ããã®ã¯ã
ãããã¯ã第1å¼æ°ã«ãããã¨ãã ãã¨ãªãã¾ãã
åèï¼
http://perl-mongers.org/2009/01/re_map.html
第81回 高階関数を理解できないとRubyは理解できない - bingo_nakanishiの他言語出身者のためのPerl入門
第139å PHPå ¥é
1ç« ãããããã°ã©ãã³ã°ãã¯ãããã
ããã«ã¡ã¯ããã³ã´ä¸è¥¿ã§ãã
ä»åã¯ãããã°ã©ãã³ã°ã¯åãã¦ã¨ããæ¹ã対象ã«ãPHPã¨ããããã°ã©ãã³ã°è¨èªã使ã£ã¦
ããã°ã©ã ã®æ¥½ãããç¥ã£ã¦ããããã¨æãã¾ããï¼æ³¨ï¼ä»åã¯Perlã§ã¯ãªãã¦PHPã§ããï¼
ãªããPHPãåãããã¨ã¯ã§ãããã©ãèªåã§ããã°ã©ã ã¨ããã®ãæ¸ãã«ã¯
ãªã«ããè¦ãã¦ãã£ããããã®ãããããªãã¨ããæ¹ã対象ã¨ãã¦ãã¾ãã
ã¾ãå®è¡
<?php print('Hello World!'); ?>
ãããä¸ã®1è¡ãã¨ãã£ã¿ã¨ãããã®ã使ã£ã¦æã£ã¦ã¿ããã
å®è¡ããã¨ã
Hello World!
ã¨è¡¨ç¤ºããã¾ãããï¼ï¼ï¼ãããã§ã¨ã大æåã§ãã
èãæ £ããªãåèªãå¾ã ã«è¦ãã¦ããã
ããã§ããã¨ãã£ã¿ãã¨ããå®è¡ãããã¨ããèãæ
£ããªãåèªãåºã¦ããã¨æãã¾ãã
åºæ¬çã«ãããã°ã©ã ã¯ããã¨ãã£ã¿ãã¨å¼ã°ããã½ããã使ã£ã¦æ¸ãã¦ããã¾ãã
ãå®è¡ãããã¨ã¯ããã°ã©ã ãåãããã¨ã§ãã
åããåãã¦ããã°ã©ã ããã£ãã¨ãã¯ã
ããã¨ãã£ã¿ãä½ãããã£ã±ãããããªãããããã°ã©ã ãã©ããã£ã¦å®è¡ãã¦ããããããããªãã
1é±éãããããã£ã¦å®è¡ã§ããè¨æ¶ãããã¾ãã
Wordã§ã¯ãªãã¨ãã£ã¿
ãããããããã°ããWordãã£ã¦ããã½ããã§æåãæã£ããã¨ãããï¼ãã¨æã£ã¦ã
ãWordãã使ã£ã¦ããã°ã©ã ãæ¸ãã¦ã¯ããã¾ããã
ããã°ã©ã ã¨ããã®ã¯ãä¸è¨ã®ããã«æåãã³ã³ãã¥ã¼ã¿ã解éãã¦ããªã«ããèµ·ããã¦ãããããã®ãªã®ã§ããã
ãWordãã§æ¸ããæç« ã¯ããWordããèªã¿è¾¼ãããã«ããã¾ãã
ããã¯ãã©ããããã¨ãã¨ããã¨ããWordãã§æ¸ããããã®ï¼ãã¡ã¤ã«ï¼ã¯ããWordãã ããç解ã§ããæ å ±ãæã£ã¦ãã¾ãã
ããã«å¯¾ãã¦ããã¨ãã£ã¿ãã¨å¼ã°ããé¨é¡ã®ãã®ã¯ããããã£ãä½è¨ãªæ
å ±ã¯ä»ãã¾ããã
ã§ããããåããæã£ãæ
å ±ã ãããã®ã¾ã¾ä¿æãã¦ããããã¨ãã£ã¿ããããã°ã©ãã³ã°ã«ã¯ãå¿
è¦ãªã®ã§ãã
2ç« print ã£ã¦ãªãã ãã
ãã¦ã
print('Hello World!');
ã¨ããã®ã詳ããè¦ã¦ãããã¨æãã¾ãã
æå¾ã® ; ï¼ã»ãã³ãã³ï¼ãªãããæ°ã«ãªãã¾ãããã
ããã°ã©ã ã¨ããã®ã¯ãè¤æ°ã®ãæãã¨ãããã®ã«ãã£ã¦æãç«ã¡ã¾ãã
åãã使ã£ã¦ããæ¥æ¬èªãªãã
ãä»æ¥ã¯ããã天æ°ã§ããã
ã¨ããã®ã§1æã§ãããæå¾ã®ããï¼å¥ç¹ï¼ããæã®çµããã示ãã¦ãã¾ãã
PHPã«ç½®ãã¦ã¯ãã;ããæã®çµããã示ãã¦ãã¾ãã
print ã¨ããã®ã¯ãç»é¢ã«æååã表示ããããã®å½ä»¤ã§ãã
ããã§ãHello World! ã¨ããæååãç»é¢ã«è¡¨ç¤ºãããããã§ãã
ããã'(ã·ã³ã°ã«ã¯ã©ã¼ãï¼ã¯è¡¨ç¤ºããã¦ãã¾ãããã
'(ã·ã³ã°ã«ã¯ã©ã¼ãï¼ã¯ããã®éã«ãããã®ããæååãã§ããã¨ãããã¨ã表ãã¦ãã¾ãã
ãããªæãã§ãããã°ã©ã è¨èªã¨ããã®ã¯ãè²ããªè¨å·ãç¨ãã¦ããæå³ãã示ããã¨ãã§ãã¾ãã
3ç« å¤æ°ã使ãã
ãå¤æ°ãã¨ãããã®ãå¦ã³ããã¨æãã¾ããããã¯ããã¸ããããã¨èªã¿ã¾ãã
ãªããªãã©ããªãã®ãæ³åãã¥ããã§ããããã£ããè¦ã¦ããã¾ãããã
ãå¤æ°ãã¨ããã®ã¯ãç®±ããã¤ã¡ã¼ã¸ããã¨ããããããã§ãã
ãã¤ã¾ã§ããç®±ãã®ã¤ã¡ã¼ã¸ã§ã¯ãæé·ï¼ããã°ã©ãã³ã°è½åï¼ã¯æ¢ã¾ã£ã¦ãã¾ãã¾ããã
ã²ã¨ã¾ããæé·ãæ¢ã¾ãã¨ããã¾ã§ã¯ããç®±ãã®ã¤ã¡ã¼ã¸ã«ãã¦ããã¾ãããã
ã§ã¯ããã®ãç®±ãã®æ©è½ãç´¹ä»ãããã¨æãã¾ãã
- ãã£ããä½ã§ãå ¥ããã
- ååãä»ããªããã°ãããªã
- ç®±ã®ä¸èº«ãã¨ãã ããã¨ãã§ãã
ãã£ã¨ãããªæãã§ãã
ããã£ããä½ã§ãå
¥ããããã®ã¨ããã§ãããããã§ã¯å¦ç¿ãã¥ããã®ã§ãä»åã¯ã
ãæ°åããå
¥ãã¦ã¿ã¾ãããã
<?php $x = 1; ?>
ããã§ã $xã¨ããååã®ãå¤æ°ãï¼ç®±ã§ããï¼ã«ãæ°åã®1ãå
¥ãã¾ããã
ã¾ãã«é©æã§ãããä½ããªãã ãã¨ããæããã¨æãã¾ãã
PHPã§ã¯å¤æ°ã§ãããã¨ã示ãããã«é ã«ã$(ãã«)ããã¤ãã¾ãã
ä»åã¯xã¨ããååã®å¤æ°ãç¨æãããã¨ã«ãªãã¾ãã
=ï¼ã¤ã³ã¼ã«ï¼ãæ°ã«ãªã
=ï¼ã¤ã³ã¼ã«ï¼ã¯ãªãã§ããããï¼é常ã«æ°ã«ãªãã¾ããã
ãã®è¨å·ã¯ãã代å
¥ãã¨ããæå³ã§ä½¿ããã¾ãã
ãã ãã«ã
ããã¨èªã¿ã¾ããã代å
¥ãã¨ã¯èãæ
£ããªãããããã¾ããããããªã«ããå
¥ãããã¨ããæå³ã§ãã
ãã¼ã=(ã¤ã³ã¼ã«ï¼ãã¯ãçãããã£ã¦ããæå³ã ããã¨åè«ãããããããã¾ãããã
ããã¯æ°å¦ã«ããã¦ã®ã話ã§ãããããã°ã©ãã³ã°è¨èªã§ã¯ãæ°å¦ã¨ã¯è¨å·ã®æå³ãå¤ãã¦ãã¾ã£ã¦ãã代å
¥ãã¨ããæå³ã§ä½¿ãã¾ãã
æ°å¦ã¨åãæå³ã§ã¯ãã==ãã¨ã¤ã³ã¼ã«ã2ã¤æ¸ããã¨ã«PHPã®ä¸çã§ã¯ãªãã¾ãã
åãã®ãã¡ã¯ããã親ãã¿ã«ããã§ãããã=ãã§ã代å
¥ããæå³ããã®ã¯ãããã°ã©ã ã®ä¸çã§ã¯å¸¸èã§ãã®ã§ãæ
£ãã¦ããã¾ãããã
ããã°ã©ããã¡ã¯ã©ãç解ãã¦ããã
ããã°ã©ãã®äººãã¡ã¯ã
$x = 1;
ã¨ããã®ãè¦ãç¬éã«ãã$xã«1ã代å
¥ãããã¨ãã®ããã°ã©ã ãèªããã¨ãã§ãã¾ãã
ããã°ã©ã ã®ä¸çã§ã¯å¤æ°ã¨ãããã®ã«å¤ã代å
¥ã§ãããã¨ãè¦ãã¾ãããã
4ç« å¤æ°ããã£ã¨ä½¿ã
ãå¤æ°ãã¨ãããã®ãåãã¦è¦ãããã§ããã
ããã§å¤æ°ã®æ©è½ãããä¸åº¦ç¢ºèªãã¦ã¿ã¾ãããã
- ãã£ããä½ã§ãå ¥ããã
- ååãä»ããªããã°ãããªã
- ç®±ã®ä¸èº«ãã¨ãã ããã¨ãã§ãã
ã§ããã
ä¸ç« ã§ã
- ãã£ããä½ã§ãå ¥ããã
- ååãä»ããªããã°ãããªã
ã®é¨åã¯èª¬æãã¾ãããã
- ç®±ã®ä¸èº«ãã¨ãã ããã¨ãã§ãã
ã®èª¬æãã¾ã ãã¦ãã¾ããã§ããã®ã§ã4ç« ã§ã¯ãã®é¨åã®èª¬æããããã¨æãã¾ãã
3ç« ã§ã
<?php $x = 1; ?>
ãæ¸ãã¾ããããæ¬å½ã«1ãå
¥ã£ãã確èªããæ¹æ³ã¯ãªãã®ã§ããããï¼
ããã¾ããprint ã使ãã¾ãããã printã¯ç»é¢ã«è¡¨ç¤ºããã¨ããæå³ã§ãããã
print($x);
ã¨ãã¦ã¿ã¾ãããã
å ¨ä½ã®ã½ã¼ã¹ï¼å 容ï¼ã¯ã
<?php $x = 1; print($x); ?>
ã¨ãªãã¾ãã
å®è¡ãã¦ã¿ã¾ãããã
1
ã¨è¡¨ç¤ºãããã°æåã§ããã
ãããªé¢¨ã«ãprintã使ããã¨ã§ãå¤æ°ã®ä¸èº«ãã¨ãã ãã¦è¦ããã¨ãã§ãã¾ããã
足ãç®ããã¦ã¿ãã
ãã¦ã
ãã¾ãå¤æ°ã«æ°åã®1ãå ¥ãã¾ããããã
ããã«8ã足ãã¦9ã¨ããå¤ãä½ãåºãã¦ã¿ã¾ãããã
<?php $x = 1; $y = $x + 8; ?>
$y = $x + 8 ã®ã¨ãããå¦ç¿ãã¤ã³ãã§ãã
$y 㯠9 ã«ãªã£ã¦ãã¾ããã
ãèªèº«ã§ã print $y; ã¨ä»ãå ãã¦ã¿ã¦ã表示ããã¦ã¿ã¦ãã ããã
åä½ã¯ãã®çµµã®ããã«$xã®å¤ãåãåºããã¦ã8ã足ããã
$yã«ä»£å
¥ããã¦ããã®ã§ãã
ã§ã¯ã次ã¯ã©ãã§ããããï¼
<?php $x = 1; $x = $x + 8; ?>
次ã®é¨åããããããã§ããã
$x = $x + 8;
ãã®å¦çãçµµã§è¡¨ãã¨ã¤ãã®ããã«ãªãã¾ãã
å ã«å³è¾ºãå¦çãããã®ã§ãï¼è©ä¾¡ãããã¨ããï¼ã
ããã¦ããã®å³è¾ºãè©ä¾¡ãããçµæã$xã«ä»£å
¥ããã¦ãã¾ãã
ã¤ã¾ãã$xãä¸æ¸ãããã¦ããã¤ã¡ã¼ã¸ã§ãã
ãã®ããã«ãå¤æ°ãã®ä¸èº«ã¯æ¸ãæãããï¼ä¸æ¸ããããï¼ãã¦ãã©ãã©ãå¤ãå¤ãã¾ãã
ããããå¤æ°ãã¨å¼ã°ããæ以ãªã®ã§ãã
第138å MONOPOLYã®ç縮ã²ã¼ã
MONOPOLYã¯ä¸æãããã¨ä½æéãåè² ãã¤ããã®ã«æéãããã£ã¦ãã¾ãã¨ããããã
ããã§ãç縮ã²ã¼ã ã¨ããã®ãåå¨ãããããã
説ææ¸ã«è¼ã£ã¦ããã®ã¯ãã¾ããã¬ã¼åã«ããããã権å©æ¸ããããã£ã¦ãã
2æãã¤ãã¬ã¼ã¤ã¼ã«é
ãããã®åå°ã®ãéãæ¯æã£ã¦ããå§ããã¨ãããã®ã ã
ã¾ãæ®éã¯ã家ã4件ç«ã¦ã¦ããããã«ã«ãããã3ã¤å»ºã¦ããããã«ã«ã§ãããã¨ããã®ãè¼ã£ã¦ãããä»ã«ãããã
ã ããããã§åé¡ã«ãããã®ã¯æ¨©å©æ¸ãããããã¨ããè¡çºã ã
権å©æ¸ã¯ã«ã©ã¼ãã¨ã«ç¨æãã¦ãããã»ãããã²ã¼ã ãåæ»ã«ãããããã¨ãã§ããã ããã
ããã§ã権å©æ¸ã¯ã©ã³ãã ã«Perlã«é¸ãã§ããããã§ã¯ãªããã
use strict; # ãã¬ã¼ã¤ã¼å my @player = ('æ¨æ', 'ç°ä¸'); # 権å©æ¸ãé ãæ° my $num = 2; my @masu = ( # ãã¼ã¯ãã¼ãã« 'å°ä¸æµ·éã', 'ãã«ãã£ãã¯éã', # éé 'ãªã¼ãã£ã³ã°éé', 'ãã³ã·ã«ããã¢éã', 'B&Oéé', 'ã·ã§ã¼ãã©ã¤ã³éé', # å ¬å ± 'é»åä¼ç¤¾', 'æ°´éä¼ç¤¾', # ã©ã¤ããã«ã¼ 'ãªãªã¨ã³ã¿ã«éã', 'ãã¼ã¢ã³ãéã', 'ã³ããã«ããéã', # ã©ã¤ããã¼ãã« 'ã»ã³ããã£ã¼ã«ãºãã¬ã¼ã¹', 'ã¹ãã¼ãéã', 'ãã¼ã¸ãã¢éã', # ãªã¬ã³ã¸ 'ã»ã³ãã¸ã§ã¼ã ã¹ãã¬ã¼ã¹', 'ããã·ã¼éã', 'ãã¥ã¼ã¨ã¼ã¯éã', # ã¬ãã 'ã±ã³ã¿ããã¼éã', 'ã¤ã³ãã£ã¢ãéã', 'ã¤ãªãã¤éã', # ã¤ã¨ãã¼ 'ã¢ãã©ã³ãã£ãã¯éã', 'ãã³ããã¼ã«éã', 'ãã¼ãã³ã¬ã¼ãã³', # ã°ãªã¼ã³ 'ãã·ãã£ãã¯éã', 'ãã¼ã¹ãã£ãã©ã¤ãéã', 'ãã³ã·ã«ããã¢éã', # ãã¼ã¯ãã«ã¼ 'ãã¼ã¯ãã¬ã¼ã¹', 'ãã¼ãã¦ã©ã¼ã¯' ); for(@player){ print $_ . 'ãã' . "\n"; for(1..$num){ print '-->'; print +(splice @masu, rand @masu , 1), "\n"; } print "\n"; }
ã ããç§ã«ã権å©æ¸ãã®è±è¨³ãæãã¦ã»ããã
ããããªãã®ã§å¤æ°åãã$masuãã«ãã¦ãã¾ã£ãã
@playerãã«ã¯ãã¬ã¼ã¤ã¼ã®ååãæ¸ãã¦ããã°ããã
$num ã«ã¯é
ããã権å©æ¸ã®æ°ãæ¸ãã°ããã
ãã¨ã¯å®è¡ããã ãã ã
æ¨æãã -->ã¹ãã¼ãéã -->ãã¥ã¼ã¨ã¼ã¯éã ç°ä¸ãã -->ãã¼ã¯ãã¬ã¼ã¹ -->ãªã¼ãã£ã³ã°éé
第137å Perlã¯ç©ºæ°ãèªãã§ãããªããPerlã«ã¯ç©ºæ°ãèªã¾ããã¨èãã
Perlã¯ç©ºæ°ãèªãè¨èªã¨ãããã¦ãã¾ãã
確ãã«æ¥½ãªè¨èªã§ããããã¦æ¥½ããè¨èªã§ãããã¾ãã
ããããããæããããã«ãªã£ãã®ã¯ãPerlãããç¨åº¦æã£ãã¨ããã«åãããããã«ãªã£ã¦ããã§ãã
Perlã¯ç©ºæ°ãèªãã§ãããï¼
Perlã空æ°ãèªãã§ãããã¨ãããªãã°ã
ããªãããããã¼ã«æ¸ããã½ã¼ã¹ã§ããããªããæã£ãéãã«åãã¦ããã¦ãããã¯ãã§ãã
ã俺ã¯ããããã¤ããã§æ¸ããã®ã«ããªãã§Perlã¯ããæã£ã¦åããªãã®ï¼ï¼ã
ãããªãã¾ãã
ã¾ãã空æ°ãèªãã¨ãããã¨ã§Perlãããããªãã
ãä»åã®å®è¡ã§ã¯ããããã¨ãããããåã®å®è¡ã¨ã¯ãªãã¨ãªãéãæ°ããããããã¡ãã£ã¨ã ãéãåãã«ãããã©ãã
ã¨è¨ããã¦ãã¾ã£ããå°ã£ã¦ãã¾ãã¾ãã
ããã°ã©ã ã§ããããæ確ãªçç±ããªãæ¯åéãåãã«ãªã£ã¦ã¯å°ãã®ã§ãã
Perlã空æ°ãèªãã£ã¦ã©ããããã¨ï¼
ã§ã¯Perlã空æ°ãèªãã¨ããã®ã¯ã©ããããã¨ãªã®ã§ããããï¼
次ã®ã½ã¼ã¹ãè¦ã¦ãã ããã
if( @c ){ }
ããã§Perlã¯é
åã®å¤§ããã0ã§ãªããã°ifã®ä¸ãå®è¡ãã¦ããã¾ãã
ããã¯ããã®ã½ã¼ã¹ãä½åå®è¡ãã¦ãåãæå³ã§ãã
Perlã¯å¸¸ã«é
åã®å¤§ããã0ã§ãªãå ´åã«ifã®ä¸ãå®è¡ãã¦ããã¾ãã
ãªããã®ãããªå¦çã«ãªãã®ã§ããããï¼
Perlã§ã¯ã
if(ãã){}
ããããã®é¨åã¯ã¹ã«ã©ã¼ãªãã¼ã«å¤ã¨ã¿ãªãã¾ãã
@cãã¹ã«ã©ã¼ãªãã¼ã«å¤ã¨ã¿ãªããã¨ãã©ã®ããã«å¦çãé²ããã¨è¨ãã¾ãã¨ã
@c â ã¹ã«ã©ã¼ã ã¨é åã®å¤§ãããâ æ°åããã¼ã«ã§è©ä¾¡ããã¨0ãªãå½ãããã§ãªããªãç
ãããªãã¾ãã
ããã¯ããããªãã¨ç¥ã£ã¦ããªãããã°ããããªã½ã¼ã¹ãæ¸ããã¨ã¯ã§ãã¾ããã
ã¤ã¾ããããã°ã©ãã¯å¼·ãæå¿ããã£ã¦ããã¯ã¹ã«ã©ã¼ãªå¤ã§ãã¼ã«ã§å¤æãã¦ï¼ã¨æã£ã¦æ¸ãã¦ããã®ã§ãã
Perlã¯ç©ºæ°ãèªãã§ãããªããPerlã«ã¯ç©ºæ°ãèªã¾ãã
Perlã¯ç©ºæ°ãèªãã§ããã¾ãããç°¡åã«ã¯èªãã§ããã¾ããã
ãã¡ããã空æ°ãèªãã§ãããããã«ãã»ã®ããããªãã¨ããã¾ããã
å
ã»ã©ã®ä¾ã ã¨ã
ãifã®ä¸ã«é
åãç½®ãã¦ããããããã¤ãã®ããããã§ãã£ã¦ããã¦ã
ã¨ãããªãã¾ãã
Perlã«æ¯ãèã£ã¦ã»ããããã«æã«ç¤ºãã®ã§ãã
ãã®æã«ç¤ºããããããè¦ãã¦ããã°ã©ã ãæ¸ãã¨ãã°ãããå¥éºãªã½ã¼ã¹ã«ãªãã®ã§ãã
ããã°ã©ãã¨Perlã®éã«ãé¿å½ã®å¼å¸ãããã¾ãã¾ãã
ä¸ç´è
ã¯èª°ããããã¾ãPerlã¨å¼å¸ãåããã¾ãããããPerlã空æ°ãèªãã¨ãããã¨ãªã®ã§ãã
Perlã®ã½ã¼ã¹ã¯ããããç°¡åã«èªããªããªããªã
Perlã®ã½ã¼ã¹ã¯çç¥ãå¤ãã¦ããã«èªããªããªãã¨è¨ããããã¨ãããã¾ãã
ã§ãããç§ã¯ãããªé¢¨ã«ã¯æãã¾ãããPerlãæ¸ãã«ã¯ããªãã®ç¥èãè¦æ±ããã¾ãã
Perlãæã«ã©ã®ããã«æ¯ãèãã®ãç¥ããªããã°ããã¾ããã
ãããç¥ããã«ãã¦ã½ã¼ã¹ã³ã¼ããçãã¾ãããã¨ã¯ã§ãã¾ããã
ããçç¥ããã½ã¼ã¹ãæ¸ã人ãããããã®äººã¯ç¥ã£ã¦ãã¾ãã
å¼·ãæå¿ããã£ã¦ãããã°ã©ã ãæ¸ãã¦ãã¾ããããã¦ãããã§ãªããã°ããã¾ããã
ããã°ã©ã èªä½ãè¦ãã¯ããã®äººã«ã¯ã¾ã çç¥ããæ¸ãæ¹ã¯ã§ãã¾ããã
ã¾ã ç¥èãã¤ãããã¨ãããããããã¾ãã
ããã°ã©ã ãè¦ããã°ããã®äººã¯ãã¢ã«ã´ãªãºã çã«ãåé·ã«ãªã£ãããã¦ãçããªã£ã¦èªã¿ã«ããã©ãããã
ä½è¨ãªå¦çããã¨ãã«ã¯éè¤ããå¦çãã¯ãã£ãããã¾ããç§ã¯ãããã£ãç¹ã®ã»ããã½ã¼ã¹ãèªã¿ã«ãããªãã®ã§ã¯ãªããã¨æãã¾ãã
第136å PHPã§ããã¯ã¿ã¤ãã³ã°
PHPã§ãã¯ã©ã¹ãã¼ã¹ã®ãªãã¸ã§ã¯ãæåãæ¸ãã¾ããã
ãããPHPã¯åçåä»ãã§ã¯ãªãã¾ããããã¨ãããã¨ã¯
ã¨ã£ã¦ãç°¡åã«ãªãã¸ã§ã¯ãæåã使ã£ã¦å¼·åãªããã°ã©ãã³ã°ãè¡ãªãã¾ãã
PHPã§ããªã¢ã¼ãã£ãºã
ããªã¢ã¼ãã£ãºã ã¯ä¾¿å©ã§ããã
ããã便å©ã§ãããããã°ã©ã ãè¶
ã¹ãã¼ãã«ãªãã¾ãã
ããã°ã©ãã³ã°ã®çºæ³ãæ¥æ¬èªã§èãããããªçºæ³ã«ãªã£ã¦å¤§å¤èªç¶ã§ãã
ãããPHPãªãããã¯ã¿ã¤ãã³ã°ã§æ¸ãã¾ãã
次ã®ã½ã¼ã¹ãè¦ã¦ãã ããã
<?php class Dog{ function say(){ print 'ãã' . "\n"; } } class Cat{ function say(){ print 'ã«ãã' . "\n"; } } $animals = array(new Dog, new Cat); foreach($animals as $animal){ $animal->say(); } ?>
Dogï¼ç¬ï¼ã¯ã©ã¹ã¨Catï¼ç«ï¼ã¯ã©ã¹ãä½ãã¾ããã
ããããã«say()ã¨ããã¡ã½ãããå®è¡ãã¦ãããããã®ã§ãforeachã使ãã¾ããã
ãã®ããã«foreachã§åãå¦çãåãããããã¯å¤§å¤ä¾¿å©ã§ãã
DogãCatãåãå¦çãããã¨ãããã¨ãä¸ç®ã§ãããã¾ãã
åèï¼第68回 関数ではなくforで処理を共通化する - bingo_nakanishiの他言語出身者のためのPerl入門
ã§ã¯ããã®ã½ã¼ã¹ãå®è¡ãã¦ã¿ã¾ãããã
çµæï¼
ãã ã«ãã
1åç®ã®ã«ã¼ãã§ããããã表示ããã
2åç®ã®ã«ã¼ãã§ãã«ãããã表示ããã¾ããã
1åç®ã®ã«ã¼ãã§ã¯æè¦çã«
Dog->say()
2åç®ã®ã«ã¼ãã§ã¯
Cat->say()
ãå®è¡ãããã¤ã¡ã¼ã¸ã§ãã
ãã㯠arrayã«å
¥ããé çªãarray(new Dog, new Cat) ãéãã§ããã
1åç®ã®ã«ã¼ãã¯Dogã®say, 2åç®ã®ã«ã¼ãã¯Catã®sayã¨ç°¡åã«ç解ã§ãã¾ãã
ãªãã¸ã§ã¯ãæåã使ããªãå ´å
ãªãã¸ã§ã¯ãæåã使ããªãã§æ¸ããå ´åãã©ã®ããã«ãªã£ã¦ãã¾ãã®ã§ããããï¼
ããã°ã©ã ãå¦ã³å§ãã¦ããã«ifæãç¿ãã¾ãã
ifæãè¦ããã ãã§ãçµæ§ããªã¨ã¼ã·ã§ã³ã«å¯ãã ããã°ã©ã ãæ¸ãããããããªãã¾ãã
ifæã§ããã°ã©ã ãå¦ã¶ãã¨ãæºè¶³ãã¦ãã¾ãã¨æ¬¡ã®ãããªã½ã¼ã¹ãæ¸ãã¦ãã¾ãããããã¾ããã
<?php $animals = array('Dog', 'Cat'); foreach($animals as $animal){ if($animal == 'Dog'){ print 'ãã' . "\n"; }else if($animal == 'Cat'){ print 'ã«ãã' . "\n"; } } ?>
ifæã§æåå'Dog'ã®å ´åãªããããã
'Cat'ã®å ´åãªããã«ãããã¨è¡¨ç¤ºããã¨ããå¦çã«ãªãã¾ããã
ãããifã®ä¸ã§ããäºãå¤ããªãã¨ã
if($animal == 'Dog'){ // ä½ç¾ãããã½ã¼ã¹ }else if($animal == 'Cat'){
ã¨ãªã£ã¦ä»ã©ãã®ifã®ä¸ãèªãã§ããã®ãããã¨è¦ã§ã¯ããããªããªã£ã¦ãã¾ãã¾ãã
ããã§'Dog'ã ã£ãå ´åã«è¡ãªãå¦çãé¢æ°ã«ãããã¨ãã¾ãã
ããããã¨ifã®ä¸ã«æ¸ãéã¯æ¸ãã¾ãã
if($animal == 'Dog'){ dog(); }else if($animal == 'Cat'){ cat(); }
é¢æ°ã«ãªã£ãããã§ããããªãã¸ã§ã¯ãæåã®å ´åã¯åããããã®é¨åãã¡ã½ããã§ãã
ä¾ï¼
$animal->do();
ããã§ãforeachã®é¨åãå«ãã¦è¦æ¯ã¹ã¦ã¿ã¾ããã
ãªãã¸ã§ã¯ãæåï¼
foreach($animals as $animal){
$animal->do();
}
ifæï¼
foreach($animals as $animal){ if($animal == 'Dog'){ print 'ãã' . "\n"; }else if($animal == 'Cat'){ print 'ã«ãã' . "\n"; } }
ã©ã¡ããèªã¿ãããã§ããããï¼
ç§ã¯ãªãã¸ã§ã¯ãæåã®æ¹ããã¡ããã¡ããã¦ããªãã¦ãã£ãããã¦ããããã«æãã¾ãã
æå³çãªéã
ããã°ã©ã ã®æå³çãªéãã¯ã©ãã§ããããï¼
ãªãã¸ã§ã¯ãæåã®æ¹ã¯ã1åç®ã®ã«ã¼ãã§ãDogã®å¦çãã2åç®ã®ã«ã¼ãã§Catã®å¦çãè¡ãªããããã¨ãã£ã¨èªãã¾ãããifæã®æ¹ã§ã¯ããCatã§ãªãã¦Dogã®å ´åãªãDogã®å¦çãDogã§ãªãã¦Catã®å ´åãªãCatã®å¦çãã¨ããããã«ããã§ãªãã¦ãã¨ããé¨åãã©ããæ°ã«ãªãã¾ãã
ãã£ã¨ifã®ãã¿ã¼ã³ãå¢ããã¨ãããã§ãªãã¦ãã§ãªãã¦ãã§ãªãã¦ãã§ãªãã¦ãã¨ãªã£ã¦èªãã®ã大å¤ã«ãªã£ã¦ãã¾ãããã§ãªãã¦ãã®é¨åã¯ããã°ã©ã çã«ã¯ãelseãã«å½ããé¨åã§ããã
ã¾ã¨ã
ãªãã¸ã§ã¯ãæåã®ãã¯ã¼ãç¥ã£ã¦ã
ãã¾ã使ãã¨æ¿çã«ã½ã¼ã¹ãå¤ãããæ¸ãçºã®æèåè·¯ãèªãçºã®æèåè·¯ãããã£ã¨å¤ããã¾ãã
ãªãã¸ã§ã¯ãæåããã¾ãã¤ãã£ã¦è¨è¨ãã§ããã¨ããªãå¼·åã«ãªãã¾ãã
ã¨ãã£ã¦ãããããã¤ãç°¡åã«æãã¤ãã¦ãµã¯ã£ã¨ã³ã¼ãã£ã³ã°ã§ããã®ãªãã°èª°ãè¨è¨ã§è¦å´ã¯ããªããªãã®ã§ãã....
è¨è¨ã®ã²ã¨ã¤ã®æ段ã¨ãã¦ãªãã¸ã§ã¯ãæåã ã¨ãã£ã¨ãã¾ãæ¸ããããã¨ããçºæ³ã¯å¤§åã ã¨æãã¾ãã
ãããã¯ã¿ã¤ãã³ã°ãç¨ããããªã¢ã¼ãã£ãºã ãã¨ãç¶æ¿ãªã©ãç¨ããããªã¢ã¼ãã£ãºã ãã®éã
ããªã¢ã¼ãã£ãºã ã®å®è£
æ¹æ³ã«ãããã¯ã¼ã®éãã¯ãã®ãããã«æ¸ãã¾ããã
第126回 ダックタイピング と インタフェース - bingo_nakanishiの他言語出身者のためのPerl入門
第127回 Ruby vs Java ダックタイピングとインタフェースで見る多態性 - bingo_nakanishiの他言語出身者のためのPerl入門
第135å Perlã« true, falseãªãã¦ãªã
ããããã®åï¼
ã ã¾ãããã¨æã£ã¦ãããå®è¡ãã¦ãããªããã
if( false ){ print "ãããã\n"; }
ã©ããªçµæã«ãªã£ãããï¼
ããã ã
ãããã
ãã表示ãããã ããã
ãã¨ã®çºç«¯
ãã®äºå®ã«æ°ã¥ããã®ã¯ãããJS使ããã
if( !false ){ print "ãããã\n"; }
ã trueã«ãªããªããã ãã©ãã©ããããã¨ï¼
ã¨è³ªåããã£ãããã ã
ã¨ããCè¨èªçµé¨è ã®çºè¨
ããããCè¨èªã«ã true, falseã¯ãªãããã
ã¨è¨ãã®ã¯ãããCè¨èªçµé¨è
ã®çºè¨ã
Cè¨èªã§ã¯ãC89 ã«ã¯ãã¼ãªã¢ã³åãå®ç¾©ããã¦ããªãï¼C99ã«ã¯å®ç¾©ããã¦ããï¼ããã¼ãªã¢ã³åããªã代ããã« true/false 㯠0 ãã©ããã§å¤æãããã
C++ã§ã¯ãæ¨æºåã®éç¨ã§ boolãtrueãfalse ã¨ãããã¼ã¯ã¼ããå°å ¥ãããåºæ¬ãã¼ã¿åã¨ãã¦ãµãã¼ããããããã®å¤§ããã¯å¦çç³»ã§å®ç¾©ãããã
ã ããã§ãã
Perlã«ã true, falseãªãã¦ãªãã®ã
Perlã®çå½å¤ã®ã«ã¼ã«ã¯ä»¥ä¸ã®ãããªæãã§ãã
Perlにおける真偽値 - Perl入門ゼミ
ã©ã¯ãæ¬ã«ããããªãã«ã¼ã«ãè¼ã£ã¦ãã¾ãããæ®å¿µãªããä¼ç¤¾ã«ç½®ãã¦ãã¦ããã®ã§åç §ã§ãã¾ããã§ããï¼ï¼
ããã°ã©ãã³ã°PerlãVOLUME1ã
- ä½è : ã©ãªã¼ã¦ã©ã¼ã«,ã¸ã§ã³ãªã¼ã¯ã³ã,ãã ã¯ãªã¹ãã£ã³ã»ã³,Larry Wall,Jon Orwant,Tom Christiansen,è¿è¤åéª
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã»ã¸ã£ãã³
- çºå£²æ¥: 2002/09/01
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 8人 ã¯ãªãã¯: 245å
- ãã®ååãå«ãããã° (125件) ãè¦ã
çµå±ã if( false ){ }ãã¯ãªãã§çãªã®ï¼
ã§ããªãã§
if( false ){ print "ãããã\n"; }
ã§
ãããã
ãã®ããã«è¡¨ç¤ºããã¦ãã¾ãã®ã§ãããã
ããã¯
ã¯ã©ã¼ãããã¦ããªãã¯ã¼ãã¯æååã¨ãã¦æ±ããããªãã§ãã
http://outsider.imawamukashi.com/Perl/pragmatic_module.html
大ä¸å¤«! use strict; ãåããå®ã£ã¦ãããã
ãï¼ãããªé¦¬é¹¿ãªè©±ãï¼ï¼
ã¨ãæãã®æ¹ï¼
ä»ã常è, use strict;ãæ¸ãã°åããå®ã£ã¦ããããã
use strict; if( false ){ print "ãããã\n"; }
çµæï¼
Bareword "false" not allowed while "strict subs" in use at e line 4. Execution of e aborted due to compilation errors.
ãããä»ã¾ã§ 1 == 1 㯠trueã¨ãæãã£ã¦ããã©ããã£ããä½ãè¿ã£ã¦ãã¦ããã ï¼
ãããtrueã¨falseããªããªãæ¯è¼æ¼ç®åã¯ãªã«ãè¿ãã¦ãã¦ããã ãã...
å®è¡ãã¦ã¿ã¾ããã
use Data::Dumper; print Dumper false; # use strictãä»ãã¦ãªãã®ã§ãæååã®'false' print Dumper true; # use strictãä»ãã¦ãªãã®ã§ãæååã®'true' print Dumper 'aa' eq 'aa'; # 1 print Dumper 1 == 1; # 1 print Dumper 'aa' ne 'aa'; # '' print Dumper 1 != 1; # '' print Dumper !('aa' eq 'aa'); # '' print Dumper !('aa' ne 'aa'); # 1
çã 㨠1
å½ã 㨠''
ã®ããã§ããã
openã¯ä½ãè¿ãã¦ããã®ã ããï¼
use strict; use Data::Dumper; # åå¨ããªããã¡ã¤ã« print Dumper open my $c, '<', 'aaaaaaaa.txt'; # undef # åå¨ãããã¡ã¤ã« print Dumper open my $c, '<', 'p.txt'; # 1
åå¨ããªããã¡ã¤ã«ã®å ´å㯠undef
åå¨ãããã¡ã¤ã«ã®å ´å㯠1ãªã®ã§ã
Perlãå½ãçã¨å¤æã§ãããã®ãã¡ããã¨è¿ã£ã¦ãã¦ãã¾ããã
ã¨ãããã¨ã§
çå½ã«ããã true, falseã¯ãã¾ããããã©ãã
äºç´èªç㪠true, falseã¯ãªãã§ããã
ã¨ããã話ã§ããã
ä»åã¯ãä¸è¨ã®ãããªã話ã§ãããããPerlã®ifã¯ä½¿ãè¾ãã¨æãããããããããã£ãããããããã¾ããããç§ã¯Perlã¯æ¥µãã¦èªç¶ã«çå½å¤ãå¤æãã¦ããã¦ããã¨æãã¾ãã
第134å ã¢ã³ãã¼ãããã³ã°ãPerlã§ããã¨ããã ããã
ã¾ã¤ãã¨ããã²ã ã³ã¼ãã®ä¸ç?ã¹ã¼ãã¼ã»ããã°ã©ãã«ãªã14ã®æèæ³
- ä½è : ã¾ã¤ãã¨ããã²ã,æ¥çµLinux
- åºç社/ã¡ã¼ã«ã¼: æ¥çµBP社
- çºå£²æ¥: 2009/05/21
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 50人 ã¯ãªãã¯: 1,711å
- ãã®ååãå«ãããã° (110件) ãè¦ã
ç°¡åã«è¨ãã¨ãã¯ã©ã¹ãå¾ããï¼å®è¡æã«ï¼æ¸ãæãã¦ãè½åã追å ãããã¨ã§ããã
èµ·æºã¯ä»äººã®ãã°ãå¾ä»ãã§åé¿ããã¨ããããå§ã¾ã£ãã¨ã®ãã¨ã§ãã
Ruby
class Bar def initialize(n) @name = n end def say1 puts @name + 'ã§ã' end end bar = Bar.new('ãã¼'); bar.say1 class Bar def say2 puts @name + 'ãããª' end end bar.say2
çµæï¼
ãã¼ã§ã ãã¼ãããª
Perl
Perlã«ã¯ã¯ã©ã¹ã¨ããã®ã¯åå¨ããããã ããã±ã¼ã¸ã«å±ããé¢æ°ãå¼ãã§ããã ããªã®ã§ã
ãã®æ¸ãæ¹ã¯ã§ãã¾ããã
use strict; package Bar; sub new { my $thing = shift; my $class = ref $thing || $thing; bless { @_ }, $class; } sub say1 { my $self = shift; print $self->{'name'} . 'ã§ã' ."\n"; } package main; my $bar = Bar->new( 'name' => 'ãã¼' ); $bar->say1(); sub say2 { my $o = shift; print $o->{'name'} . 'ãããª' . "\n"; } say2($bar);
çµæï¼
ãã¼ã§ã ãã¼ãããª
ãã®ããã«say2é¢æ°ãä½ã£ã¦ããªãã¸ã§ã¯ãæåã®æ¸ãæ¹ãå´©ãããæ¹æ³ã¯ãªãã®ã§ããããï¼
第1å¼æ°ã¯æé»çã«è£ãããæ¸å¼ãæãåºãã¦ã¿ã
$o->say();
ã¨ããæ¸ãæ¹ãããå ´åã$oãsayã¡ã½ããã®ç¬¬1å¼æ°ã«æ¸¡ãäºãæãåºãã¦ã¿ãã¨ã
use strict; package Bar; sub new { my $thing = shift; my $class = ref $thing || $thing; bless { @_ }, $class; } sub say1 { my $self = shift; print $self->{'name'} . 'ã§ã' ."\n"; } package main; my $bar = Bar->new( 'name' => 'ãã¼' ); $bar->say1(); sub say2 { my $o = shift; print $o->{'name'} . 'ãããª' . "\n"; } $bar->main::say2(); # ããããªãã¸ã§ã¯ãæåã£ã½ãæ¸ãã
çµæï¼
ãã¼ã§ã ãã¼ãããª
ãã®ããã«ãªãã¸ã§ã¯ãæåã®æ¸ãæ¹ã§æ¸ãã¾ããã
çµå±ã®ã¨ããããã¯ãã¤ã³ã¹ã¿ã³ã¹å¤æ°ã«ãããã¢ããå±ãã¦ããããã±ã¼ã¸ã®é¢æ°ãå¼ã¶ããã§ã¯ãªããå¼·å¼ã«mainããã±ã¼ã¸ã®é¢æ°ãå¼ã³åºãæ¸ãæ¹ããã¦ããã ãã§ãã®ã§ãããã¾ã§ããå¿
è¦ããããã¯ããããæªããã¨ãããããã¾ããããã®ããã«ãæ¸ãã¾ãã¨ãããã¨ã§ããã
ããããRubyã¯ã¯ã©ã¹ãç·¨éãã¦ãã
ããããRubyã¯ã¯ã©ã¹ãç·¨éã§ãã¦ããã®ã§ãããããããã®ã¯ã©ã¹ãå ã«newãããã®ã¯è¿½å ãããã¡ã½ãããå¼ã¹ã¾ãã
class Bar def initialize(n) @name = n end def say1 puts @name + 'ã§ã' end end bar = Bar.new('ãã¼') bar.say1 class Bar def say2 puts @name + 'ãããª' end end bar.say2 other_bar = Bar.new('ä»ã®ãã¼') other_bar.say1() other_bar.say2()
çµæï¼
ãã¼ã§ã ãã¼ãã㪠ä»ã®ãã¼ã§ã ä»ã®ãã¼ãããª
ãªã¼ãã³ã¯ã©ã¹ãããã§ãã
Perlã¯ããã¾ã§ãmainã®say2ãå¼ãã ã ãã§ãã®ã§ã
$other_bar = Bar->new( 'name' => 'ä»ã®ãã¼' );
ã¨ããã¨ããã§ã
$other_bar->main::say2();
ã¨ããªããã°ãªãã¾ãã....
â»ãã£ã¨è¯ãæ¹æ³ãããããã®æ¹æ³ã ã¨ããããªä¸å ·åãã§ããã¨ãããã¨ããåç¥ã®æ¹ãããã£ãããã¾ãããæãã¦ããã ããã¨ããããã§ãã