[Perl] Perl5ÆþÌç
¡ãµ¹æ¡ä
; ¼°¤Î¸å¤í¤Ëɬ¤ºÉ¬Íס£¼°¤Î¸å¤í¤Ë;¤ÎÉÕ¤¤¤¿¤â¤Î¤ò¡Öʸ¡×¤È¤¤¤¦¡£
ex)print "Hello!";
# ¹ÔËö¤Þ¤Ç¥³¥á¥ó¥È¤È¤ß¤Ê¤¹¡£
ex)# comment
" ʸ»úÎó°úÍÑÉä
ex)print "Hello!!";
$xxx ʸ»úÎó¤È¿ôÃͤòµÏ¿¤Ç¤¤ëÊÑ¿ô¡£
ex)$name = "john";
$value = 100;
>,< 2¤Ä¤Î¿ôÃͤòÈæ³Ó¤¹¤ë
ex)if ($first > $second) {
print "$first is greater than $second.";
} elsif ($first < $second) {
print "$first is less than $second.";
} else {
print "$first is equal to $second."
}
++ ¿ôÃͤΥ¤¥ó¥¯¥ê¥á¥ó¥È¡£$count++¤Ï$count = $count +1¤Î¾Êά·Á¡£
ex)$lineno++;
-- ¿ôÃͤΥǥ¯¥ê¥á¥ó¥È¡£$count--¤Ï$count = $count -1¤Î¾Êά·Á¡£
ex)$lineno--;
$_ ÈÆÍѤΰì»þÊÑ¿ô¡£Perl¤ÎÁȤ߹þ¤ßÌ¿Îá¤Î¿¤¯¤Ç¤Ï°ú¿ô¤ò¾Êά¤¹¤ë¤È$_¤¬»È¤ï¤ì¤ë¡£
ex)while(){ #¥Ï¥ó¥É¥ëIN¤«¤é°ì¹Ô¼èÆÀ¤·¼«Æ°Åª¤Ë$_¤ØÂåÆþ¡£
print OUT "$.:$_";
}
$. ľÁ°¤ËÍøÍѤ·¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤«¤é²¿¹ÔÆɤ߹þ¤ó¤À¤«¤òµÏ¿¡£
ex)while(){
print OUT "$.:$_"; #¥Ï¥ó¥É¥ëIN¤«¤éÆɤ߹þ¤ó¤À¹Ô¿ô¤¬$.¤ËÂåÆþ¤µ¤ì¤Æ¤¤¤ë¡£
}
$! ¥·¥¹¥Æ¥à¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òÊÝ»ý¤¹¤ë¡£
ex)open(IN,"this.pl") || die "this.pl:$!";
¥Ï¥ó¥É¥ë
ex)while ($l = ) {
print $l;
}
ɸ½àÆþÎÏ(¥¡¼¥Ü¡¼¥É)¤«¤é°ì¹ÔÆɤ߽Ф·¤Æ¡¢Ê¸»úÎó¤È¤·¤ÆÊֵѤ¹¤ë¡£
ex)$name=;
¡ã´Ø¿ô¡ä
chomp ¹ÔËö¤Î²þ¹Ôʸ»ú("\n")¤òÀÚ¤ê¼Î¤Æ¤ë´Ø¿ô¡£
ex)chomp ;
print ʸ»úÎó½ÐÎÏ¡£Ê¸»úÎó¤ò¥«¥ó¥Þ(,)¤Ç·Ò¤²¤Æ½ÐÎϤ¹¤ë¤³¤È¤â¤Ç¤¤ë¡£
ex)print "Hello ", $name, "!\n"; #ɸ½à½ÐÎϤ˽ÐÎÏ
print OUT "$lineno : $l"; #¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ëOUT¤Ë½ÐÎÏ
open ¥Õ¥¡¥¤¥ë¤ò¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ë·ë¹ç¤¹¤ë¡£¥Õ¥¡¥¤¥ë̾¤ÎÁ°¤Ë">"¤¬¤Ä¤¤¤Æ¤¤¤ë¾ì¹ç¡¢½ÐÎÏÍѥϥó¥É¥ë¤Ë·ë¹ç¤¹¤ë¡£
ex)open(IN,"this.pl") || die "cannot open file";
open(OUT,">that.pl") || die "cannot open file";
close ¥Õ¥¡¥¤¥ë¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
ex)close(IN);
close(OUT);