ÆüËܸì perl texinfo ¥Ð¡¼¥¸¥ç¥ó 4.035.1
¤³¤ÎÆüËܸì perl texinfo ¤Ï¡¢ ´ðËÜŪ¤Ë perl 4.0 ¥Ñ¥Ã¥Á¥ì¥Ù¥ë 35 ¤Î¥ª¥ó¥é¥¤¥ó¥Þ¥Ë¥å¥¢¥ë¤òÆüËܸìÌõ¤·¡¢ ¤½¤Î¥»¥¯¥·¥ç¥óʬ¤±¤ËÂбþ¤·¤¿¥Î¡¼¥É¤Ëʬ³ä¤·¤¿¤â¤Î¤Ç¤¹¡£ ´Ø¿ô¤ÎÀâÌÀ¤Î¥Î¡¼¥É¤Ê¤É¡¢Ä¹¤¹¤®¤ë¤ÈȽÃǤ·¤¿¥Î¡¼¥É¤Ï¡¢ »ä¤¬¾¡¼ê¤Ëʬ³ä¤·¤Þ¤·¤¿¡£¤Ê¤ª¡¢´Ø¿ô¤ÎʬÎà¤Ë¤Ï¡¢ comp.lang.perl ¤Ëή¤ì¤Æ¤¤¤¿ `Perl Reference Guide' ¤ò»²¹Í¤Ë¤·¤Þ¤·¤¿¡£
¤´Í÷¤Ë¤Ê¤ì¤Ð¤ª¤ï¤«¤ê¤Î¤è¤¦¤Ë¡¢¤¢¤Á¤³¤Á¤Ë ? ¥Þ¡¼¥¯¤ä¸¶Ê¸¤Î°úÍѤ¬¤¢¤ê¤Þ¤¹¡£ ¤³¤ì¤Ï¡¢»ä¤¬ÆüËܸì¤ËÌõ¤»¤Ê¤«¤Ã¤¿¤ê¡¢¼«¿®¤¬¤Ê¤«¤Ã¤¿¤ê¡¢ Ìõ¤»¤Æ¤â°ÕÌ£¤¬Ê¬¤«¤é¤Ê¤«¤Ã¤¿¤ê¤·¤¿¤â¤Î¤Ç¤¹¡£ ¤´Í÷¤Î³§Íͤ¬¤³¤ì¤é¤ò°ì¤Ä¤Ç¤â¸º¤é¤¹¤³¤È¤Ë¤´¶¨ÎϤ¤¤¿¤À¤±¤ì¤ÐÈó¾ï¤Ë¹¬¤¤¤Ç¤¹¡£
¤Þ¤¿¡¢ÆüËܸìÌõ¤Ë¤¢¤¿¤Ã¤Æ¤Ï¡¢¤¿¤È¤¨ÆüËܸì¤È¤·¤Æ¤Þ¤º¤¯¤Æ¤â µ»½ÑŪ¤Ë´Ö°ã¤Ã¤Æ¤¤¤Ê¤¤Ìõ¤òÌܻؤ·¤¿¤Ä¤â¤ê¤Ç¤¹¤¬¡¢ »ä¤¬ UNIX ¤ò¿¼¤¯Íý²ò¤·¤Æ¤¤¤Ê¤¤¤³¤È¤«¤é¤¯¤ë´ª°ã¤¤¤â¤¢¤ë¤È»×¤¤¤Þ¤¹¡£ ¤³¤ÎÅÀ¤â»ØŦ¤¤¤¿¤À¤±¤ì¤Ð¹¬¤¤¤Ç¤¹¡£
¤Ç¤Ï¡¢perl life ¤ò¤ª³Ú¤·¤ß²¼¤µ¤¤¡£
(Ê䤽¤Î1)
`Perl Reference Guide' ¤Îºî¼Ô¤Ï jv@mh.nl ¤Ç¤¹¡£
ºÇ¿·ÈÇ¤Ï Perl 4.0 patchlevel 19 ¤ËÂбþ¤·¤Æ¤¤¤Þ¤¹¡£
comp.lang.perl ¤Ë¥Ý¥¹¥È¤µ¤ì¤¿»þ¤Î¥á¥Ã¥»¡¼¥¸ID¤ò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£
<1992Feb19.153340.15645@pronto.mh.nl> (PostScript ¥¥Ã¥È part 0 of 4) <1992Feb19.153749.15960@pronto.mh.nl> (PostScript ¥¥Ã¥È part 1 of 4) <1992Feb19.153823.16023@pronto.mh.nl> (PostScript ¥¥Ã¥È part 2 of 4) <1992Feb19.153855.16086@pronto.mh.nl> (PostScript ¥¥Ã¥È part 3 of 4) <1992Feb19.153936.16149@pronto.mh.nl> (PostScript ¥¥Ã¥È part 4 of 4) <1992Feb19.153425.15708@pronto.mh.nl> (LaTex ¥¥Ã¥È part 0 of 3) <1992Feb19.153528.15771@pronto.mh.nl> (LaTex ¥¥Ã¥È part 1 of 3) <1992Feb19.153607.15834@pronto.mh.nl> (LaTex ¥¥Ã¥È part 2 of 3) <1992Feb19.153702.15897@pronto.mh.nl> (LaTex ¥¥Ã¥È part 3 of 3)
(Ê䤽¤Î2)
comp.lang.perl ¤Ë¤ª¤¤¤Æ¤Ï±Ñ¸ìÈÇ texinfo ¤Î¥¢¥Ê¥¦¥ó¥¹¤â¥Ý¥¹¥È¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢
¤³¤ÎÆüËܸì perl texinfo ¤Ï¤½¤ì¤È¤ÏÆÈΩ¤ËºîÀ®¤·¤¿¤â¤Î¤Ç¤¢¤ê¡¢
²¿¤Î´Ø·¸¤â¤¢¤ê¤Þ¤»¤ó¡£¼ÂºÝ¡¢¥»¥¯¥·¥ç¥óʬ¤±¡¦´Ø¿ô¤ÎʬÎà¤Ê¤É¤¬°Û¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
±Ñ¸ìÈÇ texinfo ¤Ï ftp.dreams.org:/pub/perl-manual ¤«¤é ftp ¤Ç¤¤Þ¤¹¤·¡¢
¹ñÆâ¤Î FTP ¥µ¥¤¥È¤Ë¤â¥¢¡¼¥«¥¤¥Ö¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
ºÇ¿·ÈÇ¤Ï Perl 4.0 patchlevel 19 ¤ËÂбþ¤·¤Æ¤¤¤Þ¤¹¡£
ºÇ¿·ÈǤϤ¤¤º¤ì¤â 92ǯ11·î21Æü¤Ë³Îǧ¤·¤Þ¤·¤¿¡£
perl -- Practical Extraction and Report Language
(Ãê½Ð & Êó¹ðÍѼÂÍÑŪ¸À¸ì)
»È¤¤Êý : perl [¥ª¥×¥·¥ç¥ó] ¥Õ¥¡¥¤¥ë̾ °ú¿ô
perl ¤ÏǤ°Õ¤Î¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ÎÁöºº¡¢¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤«¤é¤Î¾ðÊó¤Î¼è¤ê½Ð¤·¡¢ ¤½¤Î¾ðÊó¤Ë´ð¤Å¤¤¤¿¥ì¥Ý¡¼¥È¤Î½ÐÎϤΤ¿¤á¤ËºÇŬ²½¤µ¤ì¤¿¥¤¥ó¥¿¡¼¥×¥ê¥¿¸À¸ì¤Ç¤¢¤ë¡£ ¤Þ¤¿¡¢¥·¥¹¥Æ¥à´ÉÍýºî¶È¤Î¿¤¯¤ËŬ¤·¤¿¸À¸ì¤Ç¤â¤¢¤ë¡£ perl ¤ÏÈþ¤·¤¤(¾®¤µ¤¤¡¢¥¨¥ì¥¬¥ó¥È¡¢ºÇ¾®)¤È¤¤¤¦¤è¤ê¤Ï ¼ÂÍÑŪ(»È¤¤¤ä¤¹¤¤¡¢¸úΨŪ¡¢´°Á´)¤Ç¤¢¤ë¡£
perl ¤Ï C¡¢sed¡¢awk¡¢sh ¤Î ºÇ¤â¤è¤¤¤È¤³¤í¤ò·ë¹ç¤·¤¿¤â¤Î¤Ç¤¢¤ë(ºî¼Ô¤Î°Õ¸þ¤È¤·¤Æ¤Ï¡¢¤Ç¤¢¤ë¤¬)¤Î¤Ç¡¢ ¤³¤ì¤é¤Î¸À¸ì¤Ë¤Ê¤¸¤ß¤Î¤¢¤ë¿Í¤Ê¤é¤Ð perl ¤ò»È¤¦¤Î¤ÏÍưפǤ¢¤í¤¦¡£ (¸À¸ìÎò»Ë³Ø¼Ô¤Ê¤é csh¡¢Pascal¡¢¤µ¤é¤Ë¤Ï BASIC-PLUS ¤Îº¯Àפ˵¤¤¬¤Ä¤¯¤À¤í¤¦¡£) ɽ¸½Ë¡¤Ï C ¤Îɽ¸½Ë¡¤Ë¤½¤Ã¤¯¤ê¤Ç¤¢¤ë¡£
ÂçȾ¤Î UNIX ¤Î¥æ¡¼¥Æ¥£¥ê¥Æ¥£¤È¤Ï°ã¤¤¡¢ perl ¤Ï¥Ç¡¼¥¿¤Î¥µ¥¤¥º¤òÀ©¸Â¤·¤Ê¤¤ -- ¥á¥â¥ê¤¬¤¢¤ë¤«¤®¤ê¡£ perl ¤Ï¥Õ¥¡¥¤¥ëÁ´ÂΤò°ì¤Ä¤Îʸ»úÎó¤È¤·¤ÆÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤ë¡£ ºÆµ¢¤Î¿¼¤µ¤âÀ©¸Â¤µ¤ì¤Ê¤¤¡£ Ï¢ÁÛÇÛÎó¤ÇÍѤ¤¤é¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤âɬÍפ˱þ¤¸¤ÆÂ礤¯¤Ê¤ë¡£ ¤³¤ì¤Ï¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤òÍî¤È¤µ¤Ê¤¤¤¿¤á¤Ç¤¢¤ë¡£
perl ¤ÏÂçÎ̤Υǡ¼¥¿¤ò¿×®¤ËÁöºº¤¹¤ë¤¿¤á¤Ë ÀöÎý¤µ¤ì¤¿¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Î¥Æ¥¯¥Ë¥Ã¥¯¤ò»È¤Ã¤Æ¤¤¤ë¡£ ¥Æ¥¥¹¥È¤òÁöºº¤¹¤ë¤Î¤ËºÇŬ²½¤µ¤ì¤Æ¤Ï¤¤¤ë¤¬¡¢perl ¤Ï¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤â°·¤¨¤ë¤·¡¢ (dbm ¤¬»È¤¨¤ë¤Ê¤é) dbm ¥Õ¥¡¥¤¥ë¤òÏ¢ÁÛÇÛÎ󤽤䯤ê¤Î·Á¤Ç°·¤¨¤ë¡£
¥Ç¡¼¥¿¥Õ¥í¡¼ÄÉÀ×µ¡¹½¤Î¤ª¤«¤²¤Ç Çϼ¯¤é¤·¤¤¥»¥¥å¥ê¥Æ¥£¥Û¡¼¥ë¤òÈò¤±¤ë¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¡¢ Setuid ¤µ¤ì¤¿ perl ¥¹¥¯¥ê¥×¥È¤Ï C ¥×¥í¥°¥é¥à¤è¤ê¤â°ÂÁ´¤Ç¤¢¤ë¡£
¤â¤·¡¢Ä̾ï¤Ê¤é sed ¤ä awk ¤ä sh ¤ò»È¤¦¤è¤¦¤ÊÌäÂê¤À¤¬ ¤·¤«¤·¤½¤ì¤é¤Ë¤Ï²Ù¤¬½Å¤¹¤®¤ë¾ì¹ç¡¢¤Þ¤¿¤Ï¤â¤¦¾¯¤·Á᤯Áö¤é¤»¤ëɬÍפ¬¤¢¤ë¤¬ ¤¯¤À¤é¤Ê¤¤¤³¤È¤ò C ¤Ç½ñ¤¤¿¤¯¤Ï¤Ê¤¤¾ì¹ç¡¢perl ¤¬¤Ô¤Ã¤¿¤ê¤À¡£ sed ¤ä awk ¤Î¥¹¥¯¥ê¥×¥È¤«¤é perl ¥¹¥¯¥ê¥×¥È¤Ø¤ÎÊÑ´¹¥×¥í¥°¥é¥à¤â¤¢¤ë¡£
¤µ¤Æ¡¢ÀëÅÁ¤Ï¤³¤ì¤Ç½¼Ê¬¤À¡£
µ¯Æ°»þ¡¢perl ¤Ï¼¡¤Î½ç½ø¤Ç¥¹¥¯¥ê¥×¥È¤òõ¤¹¡£
-e
¥¹¥¤¥Ã¥Á¤Ç 1 ¹Ô¤º¤Ä»ØÄꤹ¤ë¥¹¥¯¥ê¥×¥È¡£
#!
»ØÄê¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¤Ï¡¢
¤³¤ÎÊýË¡¤Ç¥¤¥ó¥¿¥×¥ê¥¿¤¬µ¯Æ°¤µ¤ì¤ë)
¥¹¥¯¥ê¥×¥È¤¬¸«¤Ä¤«¤ë¤È¡¢perl ¤Ï¤½¤ì¤òÆâÉô·Á¼°¤Ë¥³¥ó¥Ñ¥¤¥ë¤¹¤ë¡£ ¥¹¥¯¥ê¥×¥È¤¬Ê¸Ë¡Åª¤ËÀµ¤·¤±¤ì¤Ð¡¢¼Â¹Ô¤µ¤ì¤ë¡£
1 ʸ»ú¥ª¥×¥·¥ç¥ó¤Ï¼¡¤Ë³¤¯¥ª¥×¥·¥ç¥ó¤¬¤¢¤ì¤Ð¡¢¤½¤ì¤È¤¯¤Ã¤Ä¤±¤Æ¤â¤è¤¤¡£
ÆÃ¤Ë #!
µ¡¹½¤ò»È¤Ã¤Æµ¯Æ°¤¹¤ë»þ¤Ï°ú¿ô¤¬°ì¤Ä¤·¤«µö¤µ¤ì¤Ê¤¤¤Î¤Ç¡¢
ÊØÍø¤Ç¤¢¤ë¡£
#!/usr/bin/perl -spi.bak # -s -p -i.bak ¤ÈƱ¤¸ ...
perl ¤Ë¤Ï°Ê²¼¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤¬¤¢¤ë¡£
-0
: ¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤Î»ØÄê`-0 ¿ô»ú'
¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿($/
)¤ò8¿Ê¿ô¤Ç»ØÄꤹ¤ë¡£See section @hbox{@hbox to 1.6em{@tt@$/@hfil} : ÆþÎϥ쥳¡¼¥É¤Î¥»¥Ñ¥ì¡¼¥¿}.
¿ô»ú¤ò»ØÄꤷ¤Ê¤¤¾ì¹ç¤Ï¥Ì¥ë¥¥ã¥é¥¯¥¿¤¬¥»¥Ñ¥ì¡¼¥¿¤Ë¤Ê¤ë¡£ ¿ô»ú¤ÎÁ°¤ä¸å¤Ë¾¤Î¥¹¥¤¥Ã¥Á¤¬¤¢¤Ã¤Æ¤â¤è¤¤¡£
Î㤨¤Ð¡¢ ¥Õ¥¡¥¤¥ë̾¤ÎºÇ¸å¤Ë¥Ì¥ë¥¥ã¥é¥¯¥¿¤òÉÕ¤±¤Æ¥×¥ê¥ó¥È¤¹¤ë find ¤¬¤¢¤ë¤Ê¤é¡¢ ¼¡¤Î¤è¤¦¤Ë»È¤¨¤ë¡£
find . -name '*.bak' -print0 | perl -n0e unlink
00
¤ÏÆüì¤ÊÃͤǡ¢perl ¤Ï¥Õ¥¡¥¤¥ë¤ò¥Ñ¥é¥°¥é¥Õ¥â¡¼¥É¤ÇÆɤ߹þ¤à¡£
0777
¤ò»ØÄꤹ¤ë¤È¡¢
¤½¤ÎÃͤò»ý¤Äʸ»ú¤Ï¤Ê¤¤¤Î¤Ç perl ¤ÏÁ´¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤à¡£
-a
: ¥ª¡¼¥È¥¹¥×¥ê¥Ã¥È¥â¡¼¥É`-a'
-n
¤ä -p
¤È°ì½ï¤ËÍѤ¤¤Æ¡¢
¥ª¡¼¥È¥¹¥×¥ê¥Ã¥È¥â¡¼¥É¤ò ON ¤Ë¤¹¤ë¡£
-n
¤ä -p
¤Ë¤è¤ê¼«Æ°Åª¤Ë¹Ô¤ï¤ì¤ë while
¥ë¡¼¥×Æâ¤Ç¡¢
ºÇ½é¤Ë¼«Æ°Åª¤Ë split
¥³¥Þ¥ó¥É¤¬¼Â¹Ô¤µ¤ì¡¢
¤½¤Î·ë²Ì¤¬ÇÛÎó @F
¤Ë¼ý¤á¤é¤ì¤ë¡£
perl -ane 'print pop(@F), "\n";'
¤Ï¼¡¤ÎÎã¤ÈƱÅù¤Ç¤¢¤ë¡£
while (<>) { @F = split(' '); print pop(@F), "\n"; }
-c
: ʸˡ¥Á¥§¥Ã¥¯`-c'
¥¹¥¯¥ê¥×¥È¤Îʸˡ¤ò¥Á¥§¥Ã¥¯¤·¡¢¼Â¹Ô¤»¤º¤Ë½ªÎ»¤¹¤ë¡£
-d
: ¥Ç¥Ð¥Ã¥°¥â¡¼¥É`-d'
perl ¥Ç¥Ð¥Ã¥¬¤Î¤â¤È¤Ç¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤¹¤ë¡£ ¥Ç¥Ð¥Ã¥¬¤Î¾Ï¤ò»²¾È¤Î¤³¤È¡£
See section perl ¥Ç¥Ð¥Ã¥¬.
-D
: ¥Ç¥Ð¥Ã¥°¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë`-D¿ô»ú'
¥Ç¥Ð¥Ã¥°¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
¥¹¥¯¥ê¥×¥È¤¬¤É¤Î¤è¤¦¤Ë¼Â¹Ô¤µ¤ì¤ë¤«¤ò¸«¤ë¤Ë¤Ï¡¢ `-D14' ¤ò»È¤¨¤Ð¤è¤¤ (¤³¤ì¤Ï¥Ç¥Ð¥Ã¥°¾ðÊó¤ò¤Ä¤±¤Æ perl ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤¿»þ¤Ë¤Î¤ßÆ°ºî¤¹¤ë)¡£
`-D1024' ¤âÍÍѤÊÃͤǤ¢¤ë¡£ ¤³¤ì¤ò»È¤¦¤È¡¢¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿Ê¸Ë¡¥Ä¥ê¡¼¤ò¥ê¥¹¥È¤¹¤ë¡£
¤Þ¤¿¡¢`-D512' ¤ò»È¤¦¤È¡¢¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿Àµµ¬É½¸½¤ò½ÐÎϤ¹¤ë¡£
-e
: ¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤é¥¹¥¯¥ê¥×¥È¤òÆþÎÏ`-e ¥³¥Þ¥ó¥É¥é¥¤¥ó'
1 ¹Ô¤Î¥¹¥¯¥ê¥×¥È¤òÆþÎϤ¹¤ë¤Î¤ËÍѤ¤¤ë¡£
Ê£¿ô¹Ô¤Î¥¹¥¯¥ê¥×¥È¤ò»ØÄꤹ¤ë¤Ë¤Ï -e
¤òÊ£¿ô»ØÄꤹ¤ì¤Ð¤è¤¤¡£
-e
¤¬»ØÄꤵ¤ì¤ë¤È¡¢
perl ¤Ï°ú¿ô¤Î¥ê¥¹¥È¤«¤é¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë̾¤òõ¤µ¤Ê¤¤¡£
-i
: ÆþÎÏ¥Õ¥¡¥¤¥ë¤ò½¤Àµ¤·¡¢¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë`-i³ÈÄ¥»Ò'
<>
¹½Â¤¤Ç½èÍý¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò¤½¤Î¾ì¤Ç½¤Àµ¤¹¤ë¤³¤È¤ò»ØÄꤹ¤ë¡£
ÆþÎÏ¥Õ¥¡¥¤¥ë¤Î̾Á°¤òÊѤ¨¤Æ¡¢½ÐÎÏ¥Õ¥¡¥¤¥ë¤ò¸µ¤Î̾Á°¤Ç¥ª¡¼¥×¥ó¤·¡¢
print
ʸ¤Î¥Ç¥Õ¥©¥ë¥È¤Î½ÐÎÏ¥Õ¥¡¥¤¥ë¤È¤¹¤ë¤³¤È¤Ç½èÍý¤¹¤ë¡£
³ÈÄ¥»Ò¤¬Í¿¤¨¤é¤ì¤ì¤Ð¡¢¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤Î̾Á°¤È¤·¤Æ ¸µ¤Î¥Õ¥¡¥¤¥ë̾¤Ë¤½¤Î³ÈÄ¥»Ò¤ò²Ã¤¨¤¿¤â¤Î¤¬»È¤ï¤ì¤ë¡£
³ÈÄ¥»Ò¤¬¤Ê¤±¤ì¤Ð¡¢¥Ð¥Ã¥¯¥¢¥Ã¥×¤Ï¤µ¤ì¤Ê¤¤¡£
perl -p -i.bak -e "s/foo/bar/;"
... ¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ï
¼¡¤Î¥¹¥¯¥ê¥×¥È¤ÈƱ¤¸¤Ç¡¢
#!/usr/bin/perl -pi.bak s/foo/bar/;
¤³¤ì¤Ï¼¡¤Î¤â¤Î¤ÈƱÅù¤Ç¤¢¤ë¡£
#!/usr/bin/perl while (<>) { if ($ARGV ne $oldargv) { rename($ARGV, $ARGV . '.bak'); open(ARGVOUT, ">$ARGV"); select(ARGVOUT); $oldargv = $ARGV; } s/foo/bar/; } continue { print; # ¸µ¤Î̾Á°¤Î¥Õ¥¡¥¤¥ë¤Ë½ÐÎϤ¹¤ë } select(STDOUT);
¤¿¤À¤·¡¢-i
¤òÍѤ¤¤¿ÊýË¡¤Ç¤Ï
¥Õ¥¡¥¤¥ë̾¤¬¤¤¤ÄÊѹ¹¤µ¤ì¤¿¤«¤òÄ´¤Ù¤ë¤¿¤á¤Ë $ARGV
¤È $oldargv
¤ò
Èæ³Ó¤¹¤ëɬÍפ¬¤Ê¤¤ÅÀ¤¬°Û¤Ê¤ë¡£-i
¤òÍѤ¤¤¿¾ì¹ç¡¢
¼ÂºÝ¤Ë¥»¥ì¥¯¥È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¤·¤Æ ARGVOUT
¤ò»È¤Ã¤Æ¤¤¤ë¡£
¥ë¡¼¥×¤Î¸å¤Ç
¥Ç¥Õ¥©¥ë¥È¤Î½ÐÎÏ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ STDOUT
¤ËÌᤵ¤ì¤Æ¤¤¤ëÅÀ¤ËÃí°Õ¡£
ÆþÎÏ¥Õ¥¡¥¤¥ë¤¹¤Ù¤Æ¤ËÄɲäò¹Ô¤Ã¤¿¤ê¡¢¹ÔÈÖ¹æ¤ò¥ê¥»¥Ã¥È¤·¤¿¤ê¤¹¤ë¾ì¹ç¡¢
³Æ¡¹¤ÎÆþÎÏ¥Õ¥¡¥¤¥ë¤Î½ª¤ï¤ê¤òÃΤ뤿¤á¤Ë eof
¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
(eof
¤Ç¤ÎÎã¤ò»²¾È¡£See section eof.)
-I
: C ¥×¥ê¥×¥í¥»¥Ã¥µ¤Ë¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë¤Î°ÌÃÖ¤òÃΤ餻¤ë`-I¥Ç¥£¥ì¥¯¥È¥ê'
-P
¤È°ì½ï¤ËÍѤ¤¤Æ C ¥×¥ê¥×¥í¥»¥Ã¥µ¤Ë
¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë¤Î°ÌÃÖ¤òÃΤ餻¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï `/usr/include' ¤È `/usr/lib/perl' ¤ò¸¡º÷¤¹¤ë¡£
-l
: ¹ÔËö½èÍý¤ò¼«Æ°Åª¤Ë¹Ô¤¦`-l 8¿Ê¿ô'
¹ÔËö½èÍý¤ò¼«Æ°Åª¤Ë¹Ô¤¦¡£Æó¤Ä¤Î¸ú²Ì¤¬¤¢¤ë:
-n
¤Þ¤¿¤Ï -p
¤È°ì½ï¤ËÍѤ¤¤¿¾ì¹ç¡¢
¹Ô¥¿¡¼¥ß¥Í¡¼¥¿¤ò¼«Æ°Åª¤Ë½ü¤¯¡£$\
¤Ë 8 ¿Ê¤ÎÃͤò¥»¥Ã¥È¤·¡¢
print ʸ¤¬Á´¤ÆºÇ¸å¤Ë¹Ô¥¿¡¼¥ß¥Í¡¼¥¿¤ò¤Ä¤±¤ë¤è¤¦¤Ë¤¹¤ë¡£
8 ¿Ê¿ô¤ò¾Êά¤¹¤ë¤È¡¢$/
¤ÎÃͤò $\
¤Ë¥»¥Ã¥È¤¹¤ë¡£Î㤨¤Ð¡¢¹Ô¤ò 80 ¥³¥é¥à¤ËÀڤ귤¨¤ë¤¿¤á¤Ë¤Ï:
perl -lpe 'substr($_, 80) = ""'
Ãí°Õ:
$\ = $/
¤ÎÂåÆþ¤Ï¥¹¥¤¥Ã¥Á¤¬½èÍý¤µ¤ì¤ë»þ¤Ë¹Ô¤Ê¤ï¤ì¤ë¤Î¤Ç¡¢
-l
¤Î¸å¤Ë -0
¤¬¤¢¤ë¾ì¹ç¡¢
ÆþÎϥ쥳¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤¬½ÐÎϥ쥳¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤È°ã¤¦Ãͤò»ý¤Ä¾ì¹ç¤¬¤¢¤ë:
gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
¤³¤Î¾ì¹ç¤Ï $\
¤ò²þ¹Ô¡¢$/
¤ò¥Ì¥ë¥¥ã¥é¥¯¥¿¤Ë¥»¥Ã¥È¤¹¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$@char'134@hfil} : print ´Ø¿ô¤ÎºÇ¸å¤Ë½ÐÎϤ¹¤ë¥»¥Ñ¥ì¡¼¥¿}, ¤ª¤è¤Ó See section @hbox{@hbox to 1.6em{@tt@$/@hfil} : ÆþÎϥ쥳¡¼¥É¤Î¥»¥Ñ¥ì¡¼¥¿}.
-n
: sed -n ¤ä awk ¤Î¥¨¥ß¥å¥ì¡¼¥È`-n'
¥¹¥¯¥ê¥×¥È¤ÎÁ°¸å¤Ë²¼¤Ë¼¨¤¹¥ë¡¼¥×¤¬¤¢¤ë¤â¤Î¤È¤·¤Æ perl ¤òµ¯Æ°¤¹¤ë¡£ ¤³¤¦¤¹¤ë¤È¡¢°ú¿ô¤Î¥Õ¥¡¥¤¥ëÁ´Éô¤Ë¤Ä¤¤¤Æ·«¤êÊÖ¤·¤¬¹Ô¤ï¤ì¤ë (sed -n ¤ä awk ¤Î¤è¤¦¤Ë)¡£
while (<>) { ... # ¥¹¥¯¥ê¥×¥È¤¬¤³¤³¤Ë¤¯¤ë }
¥Ç¥Õ¥©¥ë¥È¤Ç¤ÏÆþÎϹԤνÐÎϤ¬¤Ê¤µ¤ì¤Ê¤¤¤³¤È¤ËÃí°Õ¡£
½ÐÎϤ·¤¿¤±¤ì¤Ð¡¢-p
¤òÍѤ¤¤ë¡£
°Ê²¼¤Ë¼¨¤¹Îã¤Ï°ì½µ´Ö°Ê¾åÁ°¤Î¥Õ¥¡¥¤¥ë¤ò¸úΨŪ¤ËÁ´¤Æ¾Ãµî¤¹¤ëÊýË¡¤Ç¤¢¤ë¡£
find . -mtime +7 -print | perl -nle 'unlink;'
¤³¤¦¤¹¤ë¤È find
¤Î -exec
¥¹¥¤¥Ã¥Á¤ò»È¤¦¤è¤ê¤â®¤¤¡£
¤Ê¤¼¤Ê¤é¡¢¥Õ¥¡¥¤¥ë̾¤¬¸«¤Ä¤«¤ë¤¿¤Ó¤Ë¥×¥í¥»¥¹¤òµ¯Æ°¤¹¤ëɬÍפ¬¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
-p
: sed ¤Î¥¨¥ß¥å¥ì¡¼¥È`-p'
¥¹¥¯¥ê¥×¥È¤ÎÁ°¸å¤Ë²¼¤Ë¼¨¤¹¥ë¡¼¥×¤¬¤¢¤ë¤â¤Î¤È¤·¤Æ perl ¤òµ¯Æ°¤¹¤ë¡£ ¤³¤¦¤¹¤ë¤È¡¢°ú¿ô¤Î¥Õ¥¡¥¤¥ëÁ´Éô¤Ë¤Ä¤¤¤Æ·«¤êÊÖ¤·¤¬¹Ô¤ï¤ì¤ë(sed ¤Î¤è¤¦¤Ë)¡£
while (<>) { ... # ¥¹¥¯¥ê¥×¥È¤¬¤³¤³¤Ë¤¯¤ë } continue { print; }
ÆþÎϹԤ¬¼«Æ°Åª¤Ë½ÐÎϤµ¤ì¤ë¤³¤È¤ËÃí°Õ¡£
½ÐÎϤ·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï -n
¤òÍѤ¤¤ë¡£
-p
¤Ï -n
¤ËÍ¥À褹¤ë¡£
-P
: ¥³¥ó¥Ñ¥¤¥ëÁ°¤Ë C ¥×¥ê¥×¥í¥»¥Ã¥µ¤òÄ̤¹`-P'
perl ¤Î¥³¥ó¥Ñ¥¤¥ë¤ÎÁ°¤Ë C ¥×¥ê¥×¥í¥»¥Ã¥µ¤òÄ̤¹¡£
(perl ¤Î¥³¥á¥ó¥È¤â cpp ¤ÎÌ¿Îá¤â #
¤Ç»Ï¤Þ¤ë¤Î¤Ç¡¢
¥³¥á¥ó¥È¤ò C ¥×¥ê¥×¥í¥»¥Ã¥µ¤¬Íý²ò¤¹¤ëñ¸ì¡¢
Î㤨¤Ð `if' ¤ä `else' ¤ä `define' ¤Ç
»Ï¤á¤Ê¤¤¤è¤¦¤Ë¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£)
-s
: ¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤Î²òÀÏ·ë²Ì¤òÊÑ¿ô¤Ë¥»¥Ã¥È¤¹¤ë`-s'
¥³¥Þ¥ó¥É¥é¥¤¥ó¤Î¥¹¥¯¥ê¥×¥È̾¤Î¸å¡¢ ¥Õ¥¡¥¤¥ë̾¤Î°ú¿ô(¤Þ¤¿¤Ï `--')¤ÎÁ°¤Î¥¹¥¤¥Ã¥Á¤Ë¤Ä¤¤¤Æ½éÊâŪ¤Ê²òÀϤò¹Ô¤¦¡£
¥¹¥¤¥Ã¥Á¤¬¸«¤Ä¤«¤ë¤È¡¢@ARGV
¤«¤é½ü¤«¤ì¡¢
Âбþ¤¹¤ëÊÑ¿ô¤ò perl ¥¹¥¯¥ê¥×¥ÈÆâ¤Ç¥»¥Ã¥È¤¹¤ë¡£
¼¡¤Î¥¹¥¯¥ê¥×¥È¤Ç¤Ï¡¢`-xyz' ¥¹¥¤¥Ã¥Á¤ò¤Ä¤±¤Æ¥¹¥¯¥ê¥×¥È¤òµ¯Æ°¤·¤¿»þ¡¢
¤Þ¤¿¤½¤Î»þ¤Î¤ß `true' ¤ò½ÐÎϤ¹¤ë¡£
#!/usr/bin/perl -s if ($xyz) { print "true\n"; }
-S
: ¥¹¥¯¥ê¥×¥È¤ò´Ä¶ÊÑ¿ô PATH
¤òÍѤ¤¤Æõ¤¹`-S'
¥¹¥¯¥ê¥×¥È¤òõ¤¹¤Î¤Ë¡¢´Ä¶ÊÑ¿ô PATH
¤òÍѤ¤¤ë
(¥¹¥¯¥ê¥×¥È̾¤¬ `/' ¤Ç»Ï¤Þ¤é¤Ê¤¤¤«¤®¤ê)¡£
¤³¤ì¤ÏÆÃ¤Ë #!
¤ò¥µ¥Ý¡¼¥È¤·¤Ê¤¤¥Þ¥·¥ó¤Ë¤ª¤¤¤Æ #!
¤ò
¥¨¥ß¥å¥ì¡¼¥È¤¹¤ë¤Î¤ËÍѤ¤¤é¤ì¤ë¡£¤½¤Î»È¤¤Êý¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
#!/usr/bin/perl eval "exec /usr/bin/perl -S $0 $*" if $running_under_some_shell;
¥·¥¹¥Æ¥à¤Ï 1 ¹ÔÌܤò̵»ë¤·¡¢¥¹¥¯¥ê¥×¥È¤ò `/bin/sh' ¤ËÅϤ¹¡£ `/bin/sh' ¤Ï perl ¥¹¥¯¥ê¥×¥È¤ò¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤È¤·¤Æ¼Â¹Ô¤·¤è¤¦¤È¤¹¤ë¡£ ¥·¥§¥ë¤Ï 2 ¹ÔÌܤòÄ̾ï¤Î¥·¥§¥ë¥³¥Þ¥ó¥É¤È¤·¤Æ¼Â¹Ô¤·¡¢ perl ¥¤¥ó¥¿¥×¥ê¥¿¤òµ¯Æ°¤¹¤ë¡£
¥·¥¹¥Æ¥à¤Ë¤è¤Ã¤Æ¤Ï $0
¤Ïɬ¤º¤·¤â¥Õ¥ë¥Ñ¥¹¤ò´Þ¤Þ¤Ê¤¤¤Î¤Ç¡¢
-S
¤òÍѤ¤¤Æ perl ¤ËɬÍפʤé¤Ð¥¹¥¯¥ê¥×¥È¤òõ¤¹¤è¤¦¤Ë»Ø¼¨¤¹¤ë¡£
perl ¤¬¥¹¥¯¥ê¥×¥È¤ò¸«¤Ä¤±¤ë¤È¡¢²òÀϤò¹Ô¤¤¡¢
ÊÑ¿ô $running_under_some_shell
¤¬¿¿¤Ë¤Ê¤ë¤³¤È¤Ï¤Ê¤¤¤Î¤Ç¡¢
2 ¹ÔÌܤò̵»ë¤¹¤ë¡£
¥Õ¥¡¥¤¥ë̾¤Ë´Þ¤Þ¤ì¤ë¥¹¥Ú¡¼¥¹¤Ê¤É¤òÀµ¤·¤¯°·¤¦¤Ë¤Ï¡¢
$*
¤è¤ê¤â ${1+"$@"
} ¤Î¤Û¤¦¤¬¤è¤¤¤À¤í¤¦¤¬¡¢
csh ¤¬²ò¼á¤¹¤ë¾ì¹ç¤Ë¤ÏÆ°ºî¤·¤Ê¤¤¡£
sh ¤Ç¤Ï¤Ê¤¯¤Æ csh ¤Çµ¯Æ°¤¹¤ë¤Ë¤Ï¡¢¤¢¤ë¥·¥¹¥Æ¥à¤Ç¤Ï #!
¹Ô¤ò
¥³¥í¥ó¤Î¤ß¤ò´Þ¤à¹Ô¤Ë½ñ¤´¹¤¨¤ëɬÍפ¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
perl ¤Ï¤³¤Î¹Ô¤ò̵»ë¤¹¤ë¡£¤½¤Î¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¤³¤ÎÊýË¡¤Ï»È¤¨¤º¡¢
¼¡¤Î¤è¤¦¤Ë¡¢csh¡¢sh¡¢perl ¤Î¤É¤ì¤Ç¤âÆ°ºî¤¹¤ë¤è¤¦¤Ê¡¢
¤È¤Æ¤â¤ä¤ä¤³¤·¤¤ÊýË¡¤ò¤È¤ëɬÍפ¬¤¢¤ë¡£
eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -S $0 $argv:q' if 0;
-u
: ¥¹¥¯¥ê¥×¥È¤Î¥³¥ó¥Ñ¥¤¥ë¸å¡¢¥³¥¢¥À¥ó¥×¤¹¤ë`-u'
¥¹¥¯¥ê¥×¥È¤Î¥³¥ó¥Ñ¥¤¥ë¤Î¸å¡¢¥³¥¢¥À¥ó¥×¤¹¤ë¡£
¤³¤Î¥³¥¢¥À¥ó¥×¤«¤é¡¢undump ¥×¥í¥°¥é¥à(Ä󶡤·¤Æ¤¤¤Ê¤¤)¤òÍѤ¤¤Æ ¼Â¹Ô²Äǽ¥Õ¥¡¥¤¥ë¤ËÊÑ´¹¤Ç¤¤ë¡£¤³¤¦¤¹¤ë¤È¡¢ ¥Ç¥£¥¹¥¯¾ÃÈñ¤¬Áý¤¨¤ë¤«¤ï¤ê¤Ë(¼Â¹Ô¥Õ¥¡¥¤¥ë¤ò strip ¤¹¤ì¤ÐºÇ¾®¤Ë¤Ç¤¤ë) ¥¹¥¿¡¼¥È¥¢¥Ã¥×¤¬Â®¤¯¤Ê¤ë¡£(¤·¤«¤·¡¢ »ä¤Î¥Þ¥·¥ó¤Ç¤Ï "hello world" ¤Î¼Â¹Ô·Á¼°¤¬ 200k ¤ÎÂ礤µ¤Ë¤Ê¤ë¡£)
¤³¤Î¼Â¹Ô·Á¼°¤ò set-id ¥×¥í¥°¥é¥à¤È¤·¤ÆÁö¤é¤»¤ë¤Î¤Ê¤é¡¢ Ä̾ï¤Î perl ¤Ç¤Ï¤Ê¤¯ `taintperl' ¤òÍѤ¤¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤¿Êý¤¬Îɤ¤¡£
¥À¥ó¥×¤¹¤ëÁ°¤Ë¼Â¹Ô¤·¤¿¤¤¥¹¥¯¥ê¥×¥È¤¬¤¢¤ë¾ì¹ç¤Ï¡¢
Âå¤ï¤ê¤Ë dump
¥³¥Þ¥ó¥É¤ò»È¤¨¤Ð¤è¤¤¡£
Ãí°Õ : undump ¤¬»È¤¨¤ë¤«¤É¤¦¤«¤Ï¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ë¤è¤ë¤Î¤Ç¡¢ ¥Þ¥·¥ó¤Ë¤è¤Ã¤Æ¤ÏÍøÍѤǤ¤Ê¤¤¤â¤Î¤â¤¢¤ë¡£See section dump.
-U
: °ÂÁ´¤Ç¤Ê¤¤Áàºî¤ò²Äǽ¤Ë¤¹¤ë`-U'
°ÂÁ´¤Ç¤Ê¤¤Áàºî¤ò²Äǽ¤Ë¤¹¤ë¡£
¸½ºß¤Î½ê¡¢"°ÂÁ´¤Ç¤Ê¤¤"Áàºî¤È¤Ï¡¢¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Î¸¢¸Â¤ÇÁö¤é¤»¤Æ¤¤¤ëºÝ
¤Ë¥Ç¥£¥ì¥¯¥È¥ê¤ò unlink
¤¹¤ë¤³¤È¡¢¤ª¤è¤Ó"±ø¤ì"¥Á¥§¥Ã¥¯¤Î·ë²Ì¡¢
·Ù¹ð¤¬½Ð¤ë¤è¤¦¤Ê setuid ¥×¥í¥°¥é¥à¤òÁö¤é¤»¤ë¤³¤È¤À¤±¤Ç¤¢¤ë¡£
See section Setuid ¥¹¥¯¥ê¥×¥È.
-v
: perl ¤Î¥Ð¡¼¥¸¥ç¥ó¤È¥Ñ¥Ã¥Á¥ì¥Ù¥ë¤òɽ¼¨¤¹¤ë`-v'
perl ¤Î¥Ð¡¼¥¸¥ç¥ó¤È¥Ñ¥Ã¥Á¥ì¥Ù¥ë¤ò½ÐÎϤ¹¤ë¡£
-w
: ¼±Ê̻Ҥ˴ؤ¹¤ë¤µ¤Þ¤¶¤Þ¤Ê·Ù¹ð¤ò½Ð¤¹`-w'
¼±Ê̻ҤˤĤ¤¤Æ°Ê²¼¤Î¾ì¹ç¤Ë·Ù¹ð¤ò½Ð¤¹¡£
-x
: ¥¹¥¯¥ê¥×¥È¤¬¥á¥Ã¥»¡¼¥¸Æâ¤ËËä¤á¹þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¤òÃΤ餻¤ë`-x¥Ç¥£¥ì¥¯¥È¥ê'
¥¹¥¯¥ê¥×¥È¤¬¥á¥Ã¥»¡¼¥¸Æâ¤ËËä¤á¹þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¤ò perl ¤ËÃΤ餻¤ë¡£
#!
¤Ç»Ï¤Þ¤ê¡¢
`perl' ¤È¤¤¤¦Ê¸»úÎó¤ò´Þ¤àºÇ½é¤Î¹Ô¤¬¸½¤ì¤ë¤Þ¤Ç¤Î¥´¥ß¤Ï̵»ë¤µ¤ì¤ë¡£
¤½¤Î¹Ô¤Ë»ØÄꤷ¤¿°ÕÌ£¤Î¤¢¤ë¥¹¥¤¥Ã¥Á¤Ï¤¹¤Ù¤ÆŬÍѤµ¤ì¤ë
(¤¿¤À¤·Ä̾ï¤Î #!
½èÍý¤ÈƱ¤¸¤¯¡¢¥¹¥¤¥Ã¥Á¤Î¤«¤¿¤Þ¤ê¤Ò¤È¤Ä¤À¤±¤Ç¤¢¤ë)¡£
¥Ç¥£¥ì¥¯¥È¥ê̾¤ò»ØÄꤹ¤ë¤È¡¢ perl ¤Ï¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤¹¤ëÁ°¤Ë¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¤ë¡£
-x
¤ÏÀèƬ¤Î¥´¥ß¤Î¤ß¤ò¼Î¤Æ¤ë¡£
¥¹¥¯¥ê¥×¥È¤Î¸å¤Ë¥´¥ß¤¬¤¢¤ë¾ì¹ç¤Ï¡¢
¥¹¥¯¥ê¥×¥È¤ò __END__
¤Ç½ª¤ï¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤
(˾¤à¤Ê¤é¡¢¥¹¥¯¥ê¥×¥È¤Ç¸å¤í¤Î¥´¥ß¤Î°ìÉô¤Þ¤¿¤ÏÁ´Éô¤ò
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë DATA
·Ðͳ¤Ç½èÍý¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¢¤ë)¡£
__END__
¤Ë¤Ä¤¤¤Æ¤Ï See section ʸ»úÎó¤Î°·¤¤.
perl ¤Ë¤Ï 3 ¼ïÎà¤Î¥Ç¡¼¥¿·¿ : ¥¹¥«¥é¡¼¡¢¥¹¥«¥é¡¼ÇÛÎ󡢤ª¤è¤ÓÏ¢ÁÛÇÛÎ󤬤¢¤ë¡£ Ä̾ï¤ÎÇÛÎó¤Ïź¤¨»ú¤¬¿ô»ú¤À¤¬¡¢Ï¢ÁÛÇÛÎó¤Î¾ì¹ç¤Ïʸ»úÎó¤Ç¤¢¤ë¡£
perl ¤Ë¤ª¤±¤ë±é»»¤äÃͤβò¼á¤Ï¡¢
±é»»¤äÃͤΥ³¥ó¥Æ¥¥¹¥È¤«¤é¤ÎÍ×µá¤Ë°Í¸¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
¼ç¤Ê¥³¥ó¥Æ¥¥¹¥È¤Ë¤Ï 3 ¤Ä : ʸ»úÎ󡢿ôÃÍ¡¢¤ª¤è¤ÓÇÛÎ󤬤¢¤ë¡£
±é»»¤ÎÃæ¤Ë¤Ï¡¢ÇÛÎó¤òÍ׵᤹¤ë¥³¥ó¥Æ¥¥¹¥È¤Ç¤ÏÇÛÎó¤ò¡¢
¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥¹¥«¥é¡¼ÃͤòÊÖ¤¹¤â¤Î¤¬¤¢¤ë¡£
(¤½¤Î¤è¤¦¤Ê±é»»»Ò¤Ë¤Ä¤¤¤Æ¤Ï¤½¤Î¥É¥¥å¥á¥ó¥È¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£)
¥¹¥«¥é¡¼ÃͤòÊÖ¤¹±é»»»Ò¤Ï¡¢
¥³¥ó¥Æ¥¥¹¥È¤¬Ê¸»úÎ󤢤뤤¤Ï¿ôÃͤΤɤÁ¤é¤òÍ׵ᤷ¤Æ¤¤¤ë¤«¤Ï¹Íθ¤·¤Ê¤¤¤¬¡¢
¥¹¥«¥é¡¼ÊÑ¿ô¤ª¤è¤Ó¥¹¥«¥é¡¼ÃͤÏ
ʸ»úÎ󤢤뤤¤Ï¿ôÃͤΥ³¥ó¥Æ¥¥¹¥È¤Î¤Õ¤µ¤ï¤·¤¤Êý¤Ë²ò¼á¤µ¤ì¤ë¡£
¥¹¥«¥é¡¼¤Ï¤½¤ì¤¬¥Ì¥ëʸ»úÎ󤢤뤤¤Ï 0 ¤Ç¤Ê¤±¤ì¤ÐÏÀÍýŪ¤Ë¿¿¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¤ë¡£
±é»»»Ò¤¬ÊÖ¤¹ÏÀÍýÃͤϿ¿¤Î¾ì¹ç¤Ï 1¡¢
µ¶¤Î¾ì¹ç¤Ï 0 ¤Þ¤¿¤Ï "
(¥Ì¥ëʸ»úÎó)¤Ç¤¢¤ë¡£
¼Â¤Ï¡¢¥Ì¥ëʸ»úÎó¤Ë¤Ï 2 ¼ïÎढ¤ë¡£
define ¤µ¤ì¤¿¤â¤Î¡¢undefined ¤Î¤â¤Î¤Ç¤¢¤ë¡£
undefined ¤Î¥Ì¥ëʸ»úÎó¤Ï¥¨¥é¡¼¤ä¡¢end of file ¤ä¡¢
½é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤ÊÑ¿ô¤äÇÛÎóÍ×ÁǤò»²¾È¤·¤è¤¦¤È¤·¤¿»þ¤Ê¤É¡¢
¼ÂºÝ¤ÎÃͤ¬Â¸ºß¤·¤Ê¤¤»þ¤ËÊ֤롣
undefined ¥Ì¥ëʸ»úÎó¤ÏºÇ½é¤Ë¤½¤ì¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢
defined ¤Ë¤Ê¤ë¤³¤È¤¬¤¢¤ë¤¬¡¢¤½¤ÎÁ°¤Ë defined()
±é»»»Ò¤òÍѤ¤¤Æ
Ãͤ¬ defined ¤«¤½¤¦¤Ç¤Ê¤¤¤«¤òÃΤ뤳¤È¤¬¤Ç¤¤ë¡£
¥¹¥«¥é¡¼ÊÑ¿ô¤Ø¤Î»²¾È¤Ï¡¢¤½¤ì¤¬ÇÛÎó¤Î°ìÉô¤Ç¤¢¤Ã¤Æ¤â¡¢ ¾ï¤Ë `$' ¤Ç»Ï¤á¤ë¡£¤¹¤Ê¤ï¤Á¡¢°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
$days # ñ½ã¤Ê¥¹¥«¥é¡¼ÊÑ¿ô $days[28] # ÇÛÎó @days ¤Î 29 ÈÖÌܤÎÍ×ÁÇ $days{'Feb'} # Ï¢ÁÛÇÛÎó¤ÎÃͤΰì¤Ä $#days # ÇÛÎó @days ¤ÎºÇ¸å¤Îź¤¨»ú
¤·¤«¤·¡¢ÇÛÎóÁ´Éô¤ä°ìÉô¤Î¼è¤ê½Ð¤·¤Ê¤É¤Ï '@' ¤Ç»Ï¤á¤ë¡£
@days # ($days[0], $days[1],... $days[n]) @days[3,4,5] # @days[3..5] ¤ÈƱ¤¸ @days{a,c} # ($days{'a'},$days{'c'}) ¤ÈƱ¤¸
¤½¤·¤ÆÏ¢ÁÛÇÛÎóÁ´Éô¤ò°·¤¦¤Ë¤Ï¡¢'%' ¤Ç»Ï¤á¤ë¡£
%days # (key1, val1, key2, val2 ...)
¤³¤ì¤é 8 ¤Ä¤Ï¤¹¤Ù¤Æº¸ÊÕÃͤȤ·¤Æ°·¤¦¤³¤È¤¬¤Ç¤¤ë¡£¤¹¤Ê¤ï¤Á¡¢ÂåÆþ²Äǽ¤Ç¤¢¤ë¡£
(¤µ¤é¤Ë¡¢¤¢¤ë¥³¥ó¥Æ¥¥¹¥È¤Ç¤ÏÂåÆþÁàºî¼«ÂΤ⺸ÊÕÃͤȤʤꤦ¤ë¡£
s
¡¢tr
¤ª¤è¤Ó chop
¤Ë¤ª¤±¤ëÎã¤ò»²¾È¤Î¤³¤È¡£)
See section s/¥Ñ¥¿¡¼¥ó/ÃÖ¤´¹¤¨/, See section tr/¸¡º÷¥ê¥¹¥È/ÃÖ´¹¥ê¥¹¥È/, ¤ª¤è¤Ó See section chop.
¥¹¥«¥é¡¼¤Ø¤ÎÂåÆþ¤ò¹Ô¤¦¤È¡¢±¦ÊÕ¤ò¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤¹¤ë¤Î¤ËÂФ·¡¢ ÇÛÎó¤äÇÛÎó¤Î°ìÉô¤Ø¤ÎÂåÆþ¤Ï±¦ÊÕ¤òÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤¹¤ë¡£
ÇÛÎó @days
¤ÎŤµ¤ò¡¢csh ¤Î¤è¤¦¤Ë¡¢
`$#days' ¤Çɾ²Á¤¹¤ë¤³¤È¤¬¤Ç¤¤ë(¼ÂºÝ¤Ë¤Ï¡¢ÇÛÎó¤ÎŤµ¤Ç¤Ï¤Ê¤¯¡¢
ºÇ¸å¤ÎÍ×ÁǤÎź¤¨»ú¤Ç¤¢¤ë¡£¤Ê¤¼¤Ê¤é¡¢Ä̾ï 0 ÈÖÌܤÎÍ×ÁǤ¬¤¢¤ë¤«¤é¤Ç¤¢¤ë)¡£
$#days
¤ØÂåÆþ¤¹¤ë¤È¡¢ÇÛÎó¤ÎŤµ¤¬ÊѤï¤ë¡£
¤³¤ÎÊýË¡¤Ë¤è¤êÇÛÎó¤ò¾®¤µ¤¯¤·¤Æ¤â¡¢¼ÂºÝ¤Ë¤ÏÃͤϲ¿¤âÇ˲õ¤µ¤ì¤Ê¤¤¡£
¤¹¤Ç¤Ë¾®¤µ¤¯¤·¤¿ÇÛÎó¤òÂ礤¯¤¹¤ë¤È¡¢¤â¤È¤â¤È¤¢¤Ã¤¿Í×ÁǤ¬¸µ¤ËÌá¤ë¡£
¤Þ¤¿¡¢Â礤¯¤Ê¤ê¤½¤¦¤ÊÇÛÎó¤ò¤¢¤é¤«¤¸¤áÂ礤¯¤·¤Æ¤ª¤¯¤È¡¢
¸úΨ¤ò¤¤¤¯¤é¤«Îɤ¯¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£(ÇÛÎó¤òÂ礤¯¤¹¤ë¤Ë¤Ï¡¢
ÇÛÎó¤ÎºÇ¸å¤òĶ¤¨¤ëÍ×ÁǤËÂåÆþ¤ò¹Ô¤¦ÊýË¡¤â¤¢¤ë¡£¤³¤ÎÊýË¡¤È¡¢
$#whatever
¤ØÂåÆþ¤¹¤ëÊýË¡¤È¤Î°ã¤¤¤Ï¡¢
´Ö¤ÎÍ×ÁǤ˥̥뤬¥»¥Ã¥È¤µ¤ì¤ë¤³¤È¤Ç¤¢¤ë¡£)
ÇÛÎó¤ÎÃæ¿È¤ò¼Î¤Æ¤Æ¶õ¤Ë¤¹¤ë¤Ë¤Ï¡¢¥Ì¥ë¥ê¥¹¥È ()
¤òÂåÆþ¤¹¤ì¤ÐÎɤ¤¡£
¼¡¤ÎÆó¤Ä¤ÏÁ´¤¯Æ±Åù¤Ç¤¢¤ë¡£
@whatever = (); $#whatever = $[ - 1;
ÇÛÎó¤ò¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤¹¤ë¤È¡¢ÇÛÎó¤ÎŤµ¤¬Ê֤롣 ¼¡¤Î¼°¤Ï¾ï¤Ë¿¿¤Ç¤¢¤ë¡£
scalar(@whatever) == $#whatever - $[ + 1;
Ï¢ÁÛÇÛÎó¤ò¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤¹¤ë¤È¡¢ ÇÛÎó¤¬Í×ÁǤò´Þ¤à¾ì¹ç¤«¤Ä¤½¤Î¾ì¹ç¤Ë¸Â¤ê¿¿¤ÎÃͤòÊÖ¤¹¡£ (Í×ÁǤ¬¤¢¤ë¾ì¹ç¤ËÊÖ¤ëÃͤÏʸ»úÎó¤Ç¡¢ »ÈÍѤ·¤Æ¤¤¤ë bucket ¤Î¿ô¤ª¤è¤Ó¥¢¥í¥±¡¼¥È¤µ¤ì¤Æ¤¤¤ë bucket ¤Î¿ô¤«¤é¤Ê¤ê¡¢ ¥¹¥é¥Ã¥·¥å¤Ç¶èÀÚ¤é¤ì¤Æ¤¤¤ë¡£)
¿¼¡¸µÇÛÎó¤ÏľÀܤϥµ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¤¬¡¢
Ï¢ÁÛÇÛÎó¤òÍѤ¤¤Æ
Ê£¿ô¤Îź¤¨»ú¤ò¥¨¥ß¥å¥ì¡¼¥È¤¹¤ëÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï $;
ÊÑ¿ô¤Î¹à¤ò»²¾È¤Î¤³¤È¡£
¤Þ¤¿¡¢Â¿¼¡¸µ¤Îź¤¨»ú¤ò 1 ¼¡¸µ¤Îź¤¨»ú¤ËÊÑ´¹¤¹¤ë¥µ¥Ö¥ë¡¼¥Á¥ó¤ò½ñ¤¯¤³¤È¤â¤Ç¤¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$;@hfil} : ¿¼¡¸µÇÛÎ󥨥ߥå¥ì¡¼¥·¥ç¥ó¤ÎºÝ¤Îź¤¨»ú¤Î¶èÀÚ¤ê}.
³Æ¡¹¤Î¥Ç¡¼¥¿·¿¤Ë±þ¤¸¤Æ¡¢¤½¤ì¤¾¤ì¤Î̾Á°¶õ´Ö¤¬¤¢¤ë¡£ ¾×Æͤò¿´ÇÛ¤¹¤ë¤³¤È¤Ê¤¯¡¢Æ±¤¸Ì¾Á°¤ò¥¹¥«¥é¡¼ÊÑ¿ô¡¢ÇÛÎó¡¢Ï¢ÁÛÇÛÎó¡¢ ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¡¢¥µ¥Ö¥ë¡¼¥Á¥ó̾¡¢¤Þ¤¿¤Ï¥é¥Ù¥ë¤Ë¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£
ÊÑ¿ô¤äÇÛÎó¤Ø¤Î»²¾È¤Ï¾ï¤Ë $
¡¢@
¡¢%
¤Ç»Ï¤Þ¤ë¤Î¤Ç¡¢
ͽÌó¸ì¤ÏÊÑ¿ô̾¤Ë¤Ä¤¤¤Æ¤Ï¼ÂºÝ¤Ë¤Ï»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
(¤·¤«¤·¡¢¥é¥Ù¥ë¤ä¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ë¤Ä¤¤¤Æ¤ÏͽÌó¸ì¤Ï»ÈÍѤǤ¤Ê¤¤¡£
Æüì¤Êʸ»ú¤Ç»Ï¤Þ¤é¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
¥Ò¥ó¥È: `open(log,'logfile')' ¤è¤ê `open(LOG,'logfile')' ¤ò
»È¤Ã¤¿Êý¤¬Îɤ¤¡£
Âçʸ»ú¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë̾¤ò»È¤¦¤È¡¢Æɤ߰פµ¤â¸þ¾å¤·¡¢
¾ÍèͽÌ󤵤ì¤ëñ¸ì¤È¤Î¾×ÆͤâÈò¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£)
Âçʸ»ú¾®Ê¸»ú¤Î¶èÊ̤ϽÅÍפǤ¢¤ë -- `FOO'¡¢`Foo'¡¢`foo' ¤Ï ¤¹¤Ù¤Æ°Û¤Ê¤ë̾Á°¤Ç¤¢¤ë¡£¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç»Ï¤Þ¤ë̾Á°¤Ï¿ô»ú¤ä²¼Àþ¤ò´Þ¤ó¤Ç¤â¤è¤¤¡£ ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç»Ï¤Þ¤é¤Ê¤¤Ì¾Á°¤Ï 1 ʸ»ú¤Ë¸Â¤é¤ì¤ë¡£ Îã: `$%' ¤ä `$$'¡£ (¤Û¤È¤ó¤É¤Î°ìʸ»ú̾¤Ï perl ¤ÎͽÌóÊÑ¿ô¤È¤·¤Æ°ÕÌ£¤¬¤¢¤ë¡£ ͽÌóÊÑ¿ô¤Ë¤Ä¤¤¤Æ¤Ï See section ͽÌóÊÑ¿ô).
¿ôÃÍʸ»úÎó¤ÏÄ̾ï¤Î¾®¿ôÅÀ¤äÀ°¿ô¤Î·Á¼°¤Çɽ¤¹¡£
12345 12345.67 .23E-10 0xffff # 16 ¿Ê 0377 # 8 ¿Ê 4_294_967_296
ʸ»úÎó¤Ï¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Þ¤¿¤Ï¥À¥Ö¥ë¥¯¥©¡¼¥È¤Ç¶èÀÚ¤é¤ì¤ë¡£ ¤³¤ì¤é¤Ï¥·¥§¥ë¤Ë¤ª¤±¤ë¥¯¥©¡¼¥È¤È¤è¤¯»÷¤Æ¤¤¤ë¡£ ¥À¥Ö¥ë¥¯¥©¡¼¥È¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ë¤Ï¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤äÊÑ¿ô¤ÎÃÖ´¹¤¬¹Ô¤ï¤ì¤ë¡£ ¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ë¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£( \' ¤È \\ ¤ò½ü¤¤¤Æ¡£)
Ä̾ï¤Î¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥åµ¬Â§¤¬²þ¹Ô¤ä¥¿¥Ö¤Ê¤É¤Îʸ»ú¤òɽ¤¹¤Î¤Ë»È¤¨¤ë¡£ ²Ã¤¨¤Æ°Ê²¼¤Î¤Á¤ç¤Ã¤ÈÊѤï¤Ã¤¿·Á¼°¤â»È¤¨¤ë¡£
\t ¥¿¥Ö \n ²þ¹Ô \r ¥ê¥¿¡¼¥ó \f ¥Õ¥©¡¼¥à¥Õ¥£¡¼¥É \b ¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹ \a ¥¢¥é¡¼¥à(¥Ù¥ë) \e ¥¨¥¹¥±¡¼¥× \033 8 ¿Êʸ»ú \x1b 16 ¿Êʸ»ú \c[ ¥³¥ó¥È¥í¡¼¥ëʸ»ú \l ¼¡¤Îʸ»ú¤ò¾®Ê¸»ú¤Ë¤¹¤ë \u ¼¡¤Îʸ»ú¤òÂçʸ»ú¤Ë¤¹¤ë \L \E ¤Þ¤Ç¤ò¾®Ê¸»ú¤Ë¤¹¤ë \U \E ¤Þ¤Ç¤òÂçʸ»ú¤Ë¤¹¤ë \E Â羮ʸ»ú¤Î½¤¾þ¤Î½ª¤ê
²þ¹Ô¤òľÀÜʸ»úÎó¤Ë½ñ¤Æþ¤ì¤ë¤³¤È¤â¤Ç¤¤ë¡£ ¤¹¤Ê¤ï¤Á¡¢Ê¸»úÎó¤Ï»Ï¤Þ¤Ã¤¿¹Ô¤È°Û¤Ê¤ë¹Ô¤Ç½ª¤ï¤ë¤³¤È¤¬¤Ç¤¤ë¡£ ¤³¤ì¤ÏÊØÍø¤Ç¤¢¤ë¤¬¡¢ºÇ¸å¤Ë¥¯¥©¡¼¥È¤ò˺¤ì¤ë¤È¡¢ ¥¯¥©¡¼¥È¤ò´Þ¤à¤«¤Ê¤êÎ¥¤ì¤¿Ê̤ιԤò¸«¤Ä¤±¤ë¤Þ¤Ç perl ¤Ï ¥¨¥é¡¼¤òÊó¹ð¤·¤Ê¤¤¤À¤í¤¦¡£
ʸ»úÎóÆâ¤ÎÊÑ¿ôÃÖ´¹¤Ï¥¹¥«¥é¡¼ÊÑ¿ô¡¦Ä̾ï¤ÎÇÛÎóÃÍ¡¦ÇÛÎó¤Î°ìÉô¤Ë¸Â¤é¤ì¤ë¡£
(¸À¤¤´¹¤¨¤ë¤È¡¢$
¤ä @
¤Ç»Ï¤Þ¤ë¼±Ê̻Ҥȡ¢
¤½¤ì¤Ë³ç¸Ì¤Ç°Ï¤Þ¤ì¤¿Åº¤¨»ú¤¬¤¢¤ë¾ì¹ç¤À¤±¤Ç¤¢¤ë¡£)
¼¡¤Î¥³¡¼¥É¤Ï `The price is $100.' ¤ò½ÐÎϤ¹¤ë¡£
$Price = '$100'; # ²ò¼á¤µ¤ì¤Ê¤¤ print "The price is $Price.\n";# ²ò¼á¤µ¤ì¤ë
Ãí°Õ:
¸å¤Ë³¤¯¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤ä¿ô»ú¤È¶èÊ̤¹¤ë¤¿¤á¤Ë¡¢
¼±Ê̻Ҥò {}
¤Ç°Ï¤¦¤³¤È¤¬¤Ç¤¤ë¡£
¤Þ¤¿¡¢¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ï
¤½¤ÎÁ°¤Îñ¸ì¤È¤Ï¥¹¥Ú¡¼¥¹¤Ç¶èÀÚ¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
¤Ê¤¼¤Ê¤é¡¢¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ï¼±Ê̻ҤȤ·¤Æ͸ú¤Êʸ»ú¤À¤«¤é¤Ç¤¢¤ë¡£
(See section ¥Ñ¥Ã¥±¡¼¥¸.)
Æüì¤Êʸ»úÎó¤¬Æó¤Ä¤¢¤ê¡¢__LINE__
¤È __FILE__
¤Ç¤¢¤ë¡£
¤³¤ì¤Ï¥×¥í¥°¥é¥à¤Î¤½¤Î»þÅÀ¤Ç¤Î¹ÔÈÖ¹æ¤È¥Õ¥¡¥¤¥ë̾¤òɽ¤¹¡£
¤³¤ì¤é¤ÏÆÈΩ¤·¤¿¥È¡¼¥¯¥ó¤È¤·¤Æ¤Î¤ß»ÈÍѤǤ¤ë¡£
ʸ»úÎóÃæ¤Ë½ñ¤Æþ¤ì¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
¤µ¤é¤Ë¡¢__END__
¤Ï¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¤Î½ªÎ»¤ÎÁ°¤Î
¥¹¥¯¥ê¥×¥È¤ÎÏÀÍýŪ¤Ê½ªÎ»¤ò¼¨¤¹¤Î¤Ë»È¤¨¤ë¡£
»Ä¤ê¤Î¥Æ¥¥¹¥È¤ÏÁ´¤Æ̵»ë¤µ¤ì¤ë¤¬¡¢
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë DATA
¤«¤éÆɤळ¤È¤¬¤Ç¤¤ë
(DATA
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï¥á¥¤¥ó¤Î¥¹¥¯¥ê¥×¥È¤«¤é¤Î¤ß¥Ç¡¼¥¿¤òÆɤá¤ë¡£
require
¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤äɾ²Á¤·¤¿Ê¸»úÎ󤫤é¤ÏÆɤá¤Ê¤¤)¡£
^D
¤È ^Z
¤Î
Æó¤Ä¤Î¥³¥ó¥È¥í¡¼¥ë¥¥ã¥é¥¯¥¿¤Ï __END__
¤ÈƱ¤¸°ÕÌ£¤Ç¤¢¤ë¡£
ʸˡŪ¤Ë²ò¼áÉÔ²Äǽ¤Êñ¸ì¤Ï
¤½¤ì¤¬¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë¤«¤Î¤è¤¦¤Ë°·¤ï¤ì¤ë¡£
¤³¤Î¤¿¤á¡¢¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¡¦¿ô»ú¡¦²¼Àþ¤Î¤ß¤«¤é¤Ê¤ëñ¸ì¤Ï
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç»Ï¤Þ¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ä¥é¥Ù¥ë¤ÈƱ¤¸¤¯¡¢¾®Ê¸»ú¤Î¤ß¤«¤é¤Ê¤ëÍç¤Îñ¸ì¤Ï
¾Íè¤ÎͽÌó¸ì¤È¾×Æͤ¹¤ë´í¸±¤¬¤¢¤ë¡£-w
¥¹¥¤¥Ã¥Á¤ò»È¤¨¤Ð¡¢
perl ¤Ï¤½¤Î¤è¤¦¤Êñ¸ì¤Ë¤Ä¤¤¤Æ·Ù¹ð¤¹¤ë¡£
ÇÛÎóÃͤò¥À¥Ö¥ë¥¯¥©¡¼¥È¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤ËÆþ¤ì¤¿¾ì¹ç¤Ï¡¢
ÇÛÎó¤ÎÁ´Í×ÁǤò $"
¤Ç¼¨¤µ¤ì¤ë¶èÀÚ¤ê(¥Ç¥Õ¥©¥ë¥È¤Ï¥¹¥Ú¡¼¥¹)
¤Ç¶èÀڤäưì¤Ä¤Ë¤·¤¿Ê¸»úÎó¤Ë¤Ê¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$"@hfil} : ÇÛÎóÃͤò " " ¤Ç°Ï¤ó¤À»þ¤ËÍ×ÁÇ´Ö¤ËÆþ¤ë¥»¥Ñ¥ì¡¼¥¿}.
(3.0 °ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Î perl ¤Ç¤Ï @
¤Ï
¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤Ç¤Ï¤Ê¤«¤Ã¤¿¤Î¤Ç¡¢
@array
¡¢$array[EXPR]
¡¢@array[LIST]
¡¢
$array{EXPR}
¡¢@array{LIST}
¤Î²ò¼á¤Ï
¥×¥í¥°¥é¥à¤Î¤É¤³¤«¤Ç»²¾È¤µ¤ì¤Æ¤¤¤ë¤«¡¢
ͽ¤á define ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Î¤ß¹Ô¤ï¤ì¤ë¡£)
¼¡¤ÎÆó¤Ä¤ÏƱÅù¤Ç¤¢¤ë¡£
$temp = join($",@ARGV); system "echo $temp"; system "echo @ARGV";
¸¡º÷¥Ñ¥¿¡¼¥ó(¤³¤ì¤Ë¤â¥À¥Ö¥ë¥¯¥©¡¼¥È¤ÈƱ¤¸ÃÖ´¹¤¬¹Ô¤ï¤ì¤ë)¤Ë¤ª¤¤¤Æ¤Ï¡¢ ¤¢¤¤¤Þ¤¤¤Ê¾ì¹ç¤¬¤¢¤ë¡£
/$foo[bar]/
¤Ï
/${foo}[bar]/
([bar]
¤ÏÀµµ¬É½¸½¤Îʸ»ú¥¯¥é¥¹)
¤È¤·¤Æ²ò¼á¤¹¤ë¤Ù¤¤«¡¢
/${foo[bar]}/
([bar]
¤ÏÇÛÎó@foo
¤Îź¤¨»ú)
¤È¤·¤Æ²ò¼á¤¹¤ë¤Ù¤¤« ?
@foo
¤¬Â¸ºß¤·¤Ê¤¤¤Ê¤é¤Ð¡¢ÌÀ¤é¤«¤Ëʸ»ú¥¯¥é¥¹¤Ç¤¢¤ë¡£
@foo
¤¬Â¸ºß¤¹¤ì¤Ð¡¢perl ¤Ï [bar]
¤Ë¤Ä¤¤¤Æ¤è¤¯¹Í¤¨¡¢
¤½¤ÎÅú¤¨¤Ï¤Û¤È¤ó¤É¤Î¾ì¹çÀµ¤·¤¤¡£¤â¤·´Ö°ã¤Ã¤¿²ò¼á¤ò¤·¤¿¤ê¡¢
¤¢¤ë¤¤¤Ï¤¢¤Ê¤¿¤¬Ã±¤ËÊм¹¶¸¤Ê¤é¤Ð¡¢
¾å¤Ç½Ò¤Ù¤¿¤è¤¦¤Ë {}
¤òÆþ¤ì¤ë¤³¤È¤ÇÀµ¤·¤¤²ò¼á¤ò¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¹Ôñ°Ì¤Î°úÍÑË¡¤Ï¥·¥§¥ë¤ÎƱÍͤÎʸˡ¤Ë´ð¤Å¤¤¤Æ¤¤¤ë¡£
<<
¤Î¸å¤Ë°úÍÑʸ¤Î½ª¤ï¤ê¤ò¼¨¤¹Ê¸»úÎó¤ò»ØÄꤹ¤ë¤È¡¢
¸½ºß¹Ô¤«¤é¤½¤Îʸ»úÎ󤬸½¤ì¤ë¤Þ¤Ç¤Î¹ÔÁ´¤Æ¤¬¤½¤ÎÃͤˤʤ롣
½ª¤ï¤ê¤ò¼¨¤¹Ê¸»úÎó¤Ï¼±Ê̻ҤǤ⡢°úÍѤ¹¤ë¥Æ¥¥¹¥È¤Ç¤â¤è¤¤¡£
°úÍѤ¹¤ë¥Æ¥¥¹¥È¤Î¾ì¹ç¡¢Ä̾ï¤Î¥¯¥©¡¼¥Æ¥£¥ó¥°¤ÈƱ¤¸¤¯
¥¯¥©¡¼¥È¤Î¼ïÎब¥Æ¥¥¹¥È¤Î°·¤¤Êý¤ò·è¤á¤ë¡£
¥¯¥©¡¼¥È¤·¤Ê¤¤¼±Ê̻ҤϥÀ¥Ö¥ë¥¯¥©¡¼¥È¤ÈƱ¤¸¤è¤¦¤ËƯ¤¯¡£
(¥¹¥Ú¡¼¥¹¤òÆþ¤ì¤¿¾ì¹ç¡¢¤½¤ì¤Ï¥Ì¥ë¼±Ê̻ҤȤ·¤Æ°·¤ï¤ì¡¢¤³¤ì¤Ï͸ú¤Ç¡¢
ºÇ½é¤Î¥Ö¥é¥ó¥¯¥é¥¤¥ó¤Ë¥Þ¥Ã¥Á¤¹¤ë¡£---
²¼¤Î Merry Christmas ¤ÎÎã¤ò¸«¤è¡£)
½ª¤ï¤ê¤ò¼¨¤¹Ê¸»úÎó¤Ï¤½¤ì¤À¤±¤Ç(¥¯¥©¡¼¥È¤ä¥¹¥Ú¡¼¥¹¤ò²ó¤ê¤Ë¤Ä¤±¤º)
¸ºß¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
print <<EOF; # Á°¤ÎÎã¤ÈƱ¤¸ The price is $Price. EOF print <<"EOF"; # ¾å¤ÎÎã¤ÈƱ¤¸ The price is $Price. EOF print << x 10; # ¥Ì¥ë¼±Ê̻Ҥ¬½ª¤ï¤ê¤ò¼¨¤¹Ê¸»úÎó Merry Christmas! print <<`EOC`; # ¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤¹¤ë echo hi there echo lo there EOC print <<foo, <<bar; # ¥¹¥¿¥Ã¥¯¤ËÀѤळ¤È¤¬¤Ç¤¤ë I said foo. foo I said bar. bar
ÇÛÎó¤Îɽ¸½¤Ï¡¢¸Ä¡¹¤ÎÃͤò¥³¥ó¥Þ¤Ç¶èÀڤꡢ³ç¸Ì ()
¤Ç°Ï¤à:
(LIST)
ÇÛÎóÃͤòÍ׵ᤷ¤Ê¤¤¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢C ¤Î¥³¥ó¥Þ±é»»»Ò¤ÈƱ¤¸¤¯¡¢ ºÇ¸å¤ÎÍ×ÁǤÎÃͤ¬ÇÛÎóɽ¸½¤ÎÃͤȤʤ롣Î㤨¤Ð¡¢
@foo = ('cc', '-E', $bar);
¤ÏÇÛÎó foo
¤ËÁ´ÇÛÎóÃͤòÂåÆþ¤¹¤ë¤¬¡¢
$foo = ('cc', '-E', $bar);
¤ÏÊÑ¿ô bar
¤ÎÃͤòÊÑ¿ô foo
¤ËÂåÆþ¤¹¤ë¡£
Ãí°Õ: ÊÑ¿ô¤È¤·¤Æ¸ºß¤¹¤ë(actual)ÇÛÎó¤Î¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ë¤ª¤±¤ëÃͤÏ
ÇÛÎó¤ÎŤµ¤Ç¤¢¤ë¡£¼¡¤ÎÎã¤Ç¤Ï $foo
¤Ë 3 ¤òÂåÆþ¤¹¤ë¡£
@foo = ('cc', '-E', $bar); $foo = @foo; # $foo ¤Ï 3 ¤Ë¤Ê¤ë
ÇÛÎóɽ¸½¤Î³ç¸Ì¤òÊĤ¸¤ëÁ°¤Ë;ʬ¤Ê¥³¥ó¥Þ¤¬¤¢¤Ã¤Æ¤âÎɤ¤¡£ ¤Ä¤Þ¤ê¡¢°Ê²¼¤Îɽ¸½¤Ï²Äǽ¤Ç¤¢¤ë¡£
@foo = ( 1, 2, 3, );
¥ê¥¹¥È¤¬É¾²Á¤µ¤ì¤ë»þ¤Ï¡¢ ¥ê¥¹¥È¤ÎÍ×ÁǤϤ¹¤Ù¤ÆÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤µ¤ì¡¢·ë²Ì¤È¤·¤ÆÆÀ¤é¤ì¤ëÇÛÎóÃͤϡ¢ ¸Ä¡¹¤ÎÍ×ÁǤ¬¥ê¥¹¥È¤Î¥á¥ó¥Ð¡¼¤Ç¤¢¤Ã¤¿¤«¤Î¤è¤¦¤Ë¥ê¥¹¥È¤ËÆþ¤ì¤é¤ì¤ë¡£ ¤Ä¤Þ¤ê¡¢ÇÛÎó¤Ï¥ê¥¹¥È¤Ë¤ª¤¤¤Æ¤Ï¶èÊ̤¬¤Ê¤¯¤Ê¤ë¡£¥ê¥¹¥È
(@foo,@bar,&SomeSub)
¤Ï @foo
, @bar
¤ÎÁ´Í×ÁÇ
¤ª¤è¤Ó SomeSub
¤È¤¤¤¦Ì¾Á°¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤¬ÊÖ¤¹Á´Í×ÁǤò´Þ¤à¡£
¥ê¥¹¥È¤ÎÃͤÏÄ̾ï¤ÎÇÛÎó¤ÈƱÍͤËź¤¨»ú¤ò¤Ä¤±¤Æ»ØÄê¤Ç¤¤ë¡£
$time = (stat($file))[8]; # stat ¤ÏÇÛÎóÃͤòÊÖ¤¹ $digit = ('a','b','c','d','e','f')[$digit-10]; return (pop(@foo),pop(@foo))[0];
ÇÛÎó¤Î¥ê¥¹¥È¤Ï¤½¤ÎÍ×ÁǤ¬Á´¤Æº¸ÊÕÃͤǤ¢¤ê¡¢ ¤«¤Ä¤½¤Î»þ¤Ë¤«¤®¤êÂåÆþ²Äǽ¤Ç¤¢¤ë¡£
($a, $b, $c) = (1, 2, 3); ($map{'red'}, $map{'blue'}, $map{'green'}) = (0x00f, 0x0f0, 0xf00);
ºÇ¸å¤ÎÍ×ÁǤÏÇÛÎóËô¤ÏÏ¢ÁÛÇÛÎó¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£
($a, $b, @rest) = split; local($a, $b, %rest) = @_;
¼ÂºÝ¤Ë¤Ï¥ê¥¹¥È¤Î¤É¤³¤ËÇÛÎó¤òÆþ¤ì¤Æ¤â¤¤¤¤¤Î¤À¤¬¡¢
¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤ÎÇÛÎó¤¬Á´¤Æ¤ÎÃͤò¼è¤Ã¤Æ¤·¤Þ¤¤¡¢
¤½¤Î¸å¤ÎÍ×ÁǤˤϥ̥ëÃͤ¬Æþ¤Ã¤Æ¤·¤Þ¤¦¡£
¤³¤ì¤Ï local()
¤Ë¤ª¤¤¤ÆÊØÍø¤«¤â¤·¤ì¤Ê¤¤¡£(See section local.)
Ï¢ÁÛÇÛÎó¤Îɽ¸½¤Ï¡¢¥¡¼¡¢ÃͤȤ·¤Æ²ò¼á¤µ¤ì¤ë¤Ù¤ÃͤΥڥ¢¤ò´Þ¤à¡£
# ¾åµ¤Î map ¤Ø¤ÎÂåÆþ¤ÈƱ¤¸¡£ %map = ('red',0x00f,'blue',0x0f0,'green',0xf00);
¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤ÎÇÛÎó¤ÎÂåÆþ¤Ï ÂåÆþ¤Î±¦ÊդΠexpression ¤Ë¤è¤êÆÀ¤é¤ì¤ëÍ×ÁǤοô¤òÊÖ¤¹¡£
$x = (($foo,$bar) = (3,2,1)); # $x ¤ò 2 ¤Ç¤Ï¤Ê¤¯ 3 ¤Ë¥»¥Ã¥È¤¹¤ë
ʸ»úÎó¤ò "
¤Ç°Ï¤ó¤À¾ì¹ç¡¢
¤Þ¤º¥À¥Ö¥ë¥¯¥©¡¼¥È¤ÈÁ´¤¯Æ±¤¸ÊÑ¿ôÃÖ´¹¤¬¹Ô¤ï¤ì¤ë¡£¼¡¤Ë¥·¥§¥ë¤Î¾ì¹ç¤ÈƱ¤¸¤¯¡¢
¥³¥Þ¥ó¥É¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¡¢¤½¤Î¥³¥Þ¥ó¥É¤Î½ÐÎϤ¬¤³¤Îµ¼»÷ɽ¸½¤ÎÃͤȤʤ롣
¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢Á´½ÐÎϤ¬Æþ¤Ã¤¿ 1 ¤Ä¤Îʸ»úÎó¤¬Ê֤롣
ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢½ÐÎϤΠ1 ¹Ô¤ò 1 Í×ÁǤȤ·¤¿ÇÛÎóÃͤ¬Ê֤롣
(¾¤Î¹Ô¥¿¡¼¥ß¥Í¡¼¥¿¤ò»È¤¦¾ì¹ç¤Ë¤Ï $/
¤ò¥»¥Ã¥È¤¹¤ë¡£)See section @hbox{@hbox to 1.6em{@tt@$/@hfil} : ÆþÎϥ쥳¡¼¥É¤Î¥»¥Ñ¥ì¡¼¥¿}.
¥³¥Þ¥ó¥É¤Ïµ¼»÷ɽ¸½¤¬É¾²Á¤µ¤ì¤ë¤¿¤Ó¤Ë¼Â¹Ô¤µ¤ì¤ë¡£
¥³¥Þ¥ó¥É¤Î¥¹¥Æ¡¼¥¿¥¹¤Ï $?
¤ËÊ֤롣(See section @hbox{@hbox to 1.6em{@tt@$?@hfil} : ¥Ñ¥¤¥×¤Î¥¯¥í¡¼¥º¡¢system ´Ø¿ô¤Ê¤É¤ÇÊ֤ä¿¥¹¥Æ¡¼¥¿¥¹}.)
csh ¤Î¾ì¹ç¤È¤Ï°Û¤Ê¤ê¡¢
Ê֤äƤ¯¤ë¥Ç¡¼¥¿¤Ë¤ÏÃÖ´¹¤Ï°ìÀÚ¹Ô¤ï¤ì¤Ê¤¤¡£ -- ²þ¹Ô¤Ï²þ¹Ô¤Î¤Þ¤Þ¤Ç¤¢¤ë¡£
¤É¤Î¥·¥§¥ë¤È¤â°Û¤Ê¤ê¡¢
¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ç°Ï¤ó¤Ç¤â¥³¥Þ¥ó¥ÉÆâ¤ÎÊÑ¿ô̾¤ÏÊÑ´¹¤µ¤ì¤Æ¤·¤Þ¤¦¡£
$
¤ò¥·¥§¥ë¤ËÅϤ¹¤Ë¤Ï¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤ò»È¤¦É¬Íפ¬¤¢¤ë¡£
<>
¤Ç°Ï¤ó¤À¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òɾ²Á¤¹¤ë¤È¡¢
¤½¤Î¥Õ¥¡¥¤¥ë¤«¤é¼¡¤Î¹Ô¤òÆɤ߹þ¤à
(²þ¹Ô¤ò´Þ¤à¤Î¤Ç¡¢EOF ¤Þ¤Ç¤Ïµ¶¤Ë¤Ê¤é¤Ê¤¤¡£
EOF ¤Î¾ì¹ç¤ÏÃͤȤ·¤Æ undefined ¤¬ÊÖ¤ë)¡£
Ä̾ï¤Ï¤½¤ÎÃͤòÊÑ¿ô¤ËÂåÆþ¤¹¤ëɬÍפ¬¤¢¤ë¤¬¡¢
°ì¤Ä¤À¤±¼«Æ°Åª¤ËÂåÆþ¤¬¹Ô¤ï¤ì¤ë¾õ¶·¤¬¤¢¤ë¡£
<¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë>
¤Î¤ß¤¬ while
¥ë¡¼¥×¤Î¾ò·ï¤Ç¤¢¤ë¾ì¹ç¤Ï¡¢
(¤½¤·¤Æ¤³¤Î¾ì¹ç¤Ë¤«¤®¤ê)ÃͤÏÊÑ¿ô $_
¤Ë¼«Æ°Åª¤ËÂåÆþ¤µ¤ì¤ë¡£
(´ñ̯¤Ë»×¤¦¤«¤âÃΤì¤Ê¤¤¤¬¡¢
¤³¤ì¤ò¤Û¤È¤ó¤É¤Î perl ¥¹¥¯¥ê¥×¥È¤Ë¤ª¤¤¤Æ»È¤¦¤Ç¤¢¤í¤¦¡£)
¤È¤Ë¤«¤¯¡¢¼¡¤ÎÎã¤ÏÁ´¤ÆƱÅù¤Ç¤¢¤ë¡£
while ($_ = <STDIN>) { print; } while (<STDIN>) { print; } for (;<STDIN>;) { print; } print while $_ = <STDIN>; print while <STDIN>;
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë STDIN
¡¢STDOUT
¡¢STDERR
¤Ï
ͽÌ󤵤ì¤Æ¤¤¤ë¡£(stdin
¡¢stdout
¡¢stderr
¤Ç¤âÆ°ºî¤¹¤ë¤¬¡¢
¥Ñ¥Ã¥±¡¼¥¸¤ÎÃæ¤Ç¤Ï¥°¥í¡¼¥Ð¥ë¤Ç¤Ï¤Ê¤¯¥í¡¼¥«¥ë¤Ê¼±Ê̻ҤȤ·¤Æ²ò¼á¤µ¤ì¤ë¤Î¤Ç¡¢
Ư¤«¤Ê¤¤¡£)
¤³¤ì¤é°Ê³°¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï open
´Ø¿ô¤òÍѤ¤¤ÆºîÀ®¤¹¤ë¡£
(See section open.)
<¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë>
¤òÇÛÎó¤òÍ׵᤹¤ë¥³¥ó¥Æ¥¥¹¥È¤ÇÍѤ¤¤ë¤È¡¢
Á´ÆþÎϹԤΠ1 ¹Ô¤¬¤½¤ì¤¾¤ì 1 Í×ÁǤȤʤëÇÛÎó¤¬Ê֤롣
¤³¤ÎÊýË¡¤ò»È¤¦¤È´Êñ¤ËµðÂç¤Ê¥Ç¡¼¥¿¶õ´Ö¤òºî¤ë¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¡¢
Ãí°Õ¤·¤Æ»È¤Ã¤¿Êý¤¬¤¤¤¤¡£
¥Ì¥ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë <>
¤ÏÆüì¤Ç¡¢
sed ¤ä awk ¤ÎÆ°ºî¤ò¥¨¥ß¥å¥ì¡¼¥È¤¹¤ë¤Î¤ËÍѤ¤¤ë¡£
<>
¤Ë¤Ï¡¢É¸½àÆþÎϤ«¡¢
¤Þ¤¿¤Ï¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ë¥ê¥¹¥È¥¢¥Ã¥×¤·¤¿Á´¥Õ¥¡¥¤¥ë¤«¤éÆþÎϤµ¤ì¤ë¡£
¤³¤ì¤Ï¼¡¤Î¤è¤¦¤ËÆ°ºî¤¹¤ë¡£
<>
¤òºÇ½é¤Ëɾ²Á¤¹¤ë¤È¡¢ÇÛÎó ARGV
¤¬¥Á¥§¥Ã¥¯¤µ¤ì¡¢
¥Ì¥ë¤Ç¤¢¤ì¤Ð¡¢$ARGV[0]
¤¬ `-' ¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£
¤³¤ì¤Ï¡¢¥ª¡¼¥×¥ó¤¹¤ë»þ¤Ëɸ½àÆþÎϤȤʤ롣
¼¡¤ËÇÛÎó ARGV
¤¬¥Õ¥¡¥¤¥ë̾¤Î¥ê¥¹¥È¤È¤·¤Æ½èÍý¤µ¤ì¤ë¡£¼¡¤Î¥ë¡¼¥×
while (<>) { ... # ³Æ¹Ô¤ËÂФ¹¤ë¥³¡¼¥É }
¤Ï¼¡¤Î perl Ūµ¿»÷¥³¡¼¥É¤ÈƱÅù¤Ç¤¢¤ë¡£
unshift(@ARGV, '-') if $#ARGV < $[; while ($ARGV = shift) { open(ARGV, $ARGV); while (<ARGV>) { ... # ³Æ¹Ô¤ËÂФ¹¤ë¥³¡¼¥É } }
°ã¤¤¤Ï¡¢Á°¼Ô¤Ï¸å¼Ô¤Û¤É½ñ¤¯¤Î¤¬ÌÌÅݤǤʤ¯¡¢¤«¤Ä¼ÂºÝ¤ËÆ°¤¯¤È¤¤¤¦ÅÀ¤Ç¤¢¤ë¡£
Á°¼Ô¤Ç¤â¼ÂºÝ¤ËÇÛÎó ARGV
¤ò¥·¥Õ¥È¤·¡¢
¸½ºß¤Î¥Õ¥¡¥¤¥ë̾¤ò $ARGV
¤ËÂåÆþ¤·¤Æ¤¤¤ë¡£
¤Þ¤¿¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë ARGV
¤â
ÆâÉô¤ÇÍѤ¤¤Æ¤¤¤ë -- <>
¤Ï <ARGV>
¤ÈÁ´¤¯Æ±¤¸°ÕÌ£¤Ç¤¢¤ê¡¢
¤³¤ì¤â¡ÖËâË¡¡×¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ç¤¢¤ë
(¾å¤Îµ¿»÷¥³¡¼¥É¤¬Æ°¤«¤Ê¤¤¤Î¤Ï¡¢
<ARGV>
¤òÉáÄ̤Υե¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¤è¤¦¤Ë°·¤Ã¤Æ¤¤¤ë¤«¤é¤Ç¤¢¤ë)¡£
ɬÍפʥե¡¥¤¥ë̾¤Î¥ê¥¹¥È¤ò´Þ¤à¤è¤¦¤Ë¤·¤Æ¤ª¤¯¤«¤®¤ê¡¢
ºÇ½é¤Î <>
¤ÎÁ°¤Ç @ARGV
¤Ë¼ê¤ò²Ã¤¨¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¹ÔÈÖ¹æ ($.
) ¤ÏÆþÎϤ¬°ì¤Ä¤ÎÂ礤ʥե¡¥¤¥ë¤Ç¤¢¤ë¤Î¤ÈƱ¤¸¤¯¡¢
·Ñ³¤·¤ÆÁý¤¨¤ë¡£
(¥Õ¥¡¥¤¥ëËè¤Ë¹ÔÈÖ¹æ¤ò¥ê¥»¥Ã¥È¤¹¤ëÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï eof
¤ÎÎã¤ò»²¾È¤Î¤³¤È¡£
See section eof.)
@ARGV
¤Ë¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È¤ò¥»¥Ã¥È¤·¤¿¤¤¾ì¹ç¤Ï¡¢¤½¤¦¤¹¤ì¤Ð¤è¤¤¡£
¥¹¥¯¥ê¥×¥È¤Ë¥¹¥¤¥Ã¥Á¤òÅϤ·¤¿¤¤¾ì¹ç¤Ï¡¢
ºÇ½é¤Ë¼¡¤Î¤è¤¦¤Ê¥ë¡¼¥×¤òÆþ¤ì¤ì¤Ð¤è¤¤¡£
while ($_ = $ARGV[0], /^-/) { shift; last if /^--$/; /^-D(.*)/ && ($debug = $1); /^-v/ && $verbose++; ... # ¤Û¤«¤Î¥¹¥¤¥Ã¥Á } while (<>) { ... # ³Æ¹Ô¤ËÂФ¹¤ë¥³¡¼¥É }
<>
¤Ï°ìÅÙ¤À¤±µ¶¤òÊÖ¤¹¡£¤³¤Î¸å¤â¤¦°ìÅٸƤ֤ȡ¢
¿·¤¿¤Ê @ARGV
¥ê¥¹¥È¤Î½èÍý¤ò¹Ô¤Ã¤Æ¤¤¤ë¤â¤Î¤È¸«¤Ê¤¹¡£
¤½¤·¤Æ¤³¤Î»þ @ARGV
¤ò
¥»¥Ã¥È¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï STDIN
¤«¤éÆþÎϤµ¤ì¤ë¡£
<>
¤ÎÃæ¤Îʸ»úÎ󤬥¹¥«¥é¡¼ÊÑ¿ô¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç
(Î㤨¤Ð <$foo>
)¡¢¤½¤ÎÊÑ¿ô¤Ï
ÆþÎϤ¬¹Ô¤ï¤ì¤ë¤Ù¤¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤òÃͤȤ·¤Æ»ý¤Ä¡£
<>
¤ÎÃæ¤Îʸ»úÎ󤬥ե¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢
ÃÖ´¹¤µ¤ì¤ë¤Ù¤¥Õ¥¡¥¤¥ë̾¥Ñ¥¿¡¼¥ó¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¡¢
¥³¥ó¥Æ¥¥¹¥È¤Ë¤è¤ê¥Õ¥¡¥¤¥ë̾¤ÎÇÛÎó¤Þ¤¿¤Ï¥ê¥¹¥ÈÆâ¤Î¼¡¤Î¥Õ¥¡¥¤¥ë̾¤¬Ê֤롣
1 ¥ì¥Ù¥ë¤Î $
¤Î²ò¼á¤ÏºÇ½é¤Ë¤Ê¤µ¤ì¤ë¤¬¡¢
¾å¤Ç½Ò¤Ù¤¿¤è¤¦¤Ë <$foo>
¤Ï
´ÖÀÜŪ¤Ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò»Ø¤¹¤Î¤Ç»È¤¨¤Ê¤¤¡£
¶¯À©Åª¤Ë¥Õ¥¡¥¤¥ë̾ÃÖ´¹¤È²ò¼á¤µ¤»¤ë¤¿¤á¤Ë¤Ï¡¢
{}
¤òÆþ¤ì¤ì¤Ð¤è¤¤: <${foo}>
¡£
while (<*.c>) { chmod 0644, $_; }
¤Ï¼¡¤ÈƱÅù¤Ç¤¢¤ë¡£
open(foo, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|"); while (<foo>) { chop; chmod 0644, $_; }
¼Â¤Ï¡¢¸½ºß¤Î½ê¡¢¸å¼Ô¤ÎÊýË¡¤Ç¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤ë¡£ (¤Ä¤Þ¤ê¡¢¥Þ¥·¥ó¾å¤Ë `/bin/csh' ¤¬¤Ê¤¤¤«¤®¤ê ¥¹¥Ú¡¼¥¹¤Ê¤É¤ò´Þ¤à¥Õ¥¡¥¤¥ë̾¤Ë¤Ä¤¤¤Æ¤Ï¤¦¤Þ¤¯Æ¯¤«¤Ê¤¤¡£) ¤â¤Á¤í¤ó¡¢¾å¤ÎÁàºî¤ò¹Ô¤¦ºÇ¤âû¤¤ÊýË¡¤Ï
chmod 0644, <*.c>;
¤Ç¤¢¤ë¡£
perl ¥¹¥¯¥ê¥×¥È¤Ï°ìÏ¢¤ÎÀë¸À¤È¥³¥Þ¥ó¥É¤«¤é¤Ê¤ë¡£ perl ¤Ë¤ª¤¤¤ÆÀë¸À¤¹¤ëɬÍפ¬¤¢¤ë¤Î¤Ï ¥ì¥Ý¡¼¥È¡¦¥Õ¥©¡¼¥Þ¥Ã¥È¤È¥µ¥Ö¥ë¡¼¥Á¥ó¤À¤±¤Ç¤¢¤ë¡£
¤³¤ì¤é¤Ë¤Ä¤¤¤Æ¤Ï¤½¤ì¤¾¤ì¥Õ¥©¡¼¥Þ¥Ã¥È¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤Î¾Ï¤ò»²¾È¤Î¤³¤È¡£ See section ¥Õ¥©¡¼¥Þ¥Ã¥È, ¤ª¤è¤Ó See section ¥µ¥Ö¥ë¡¼¥Á¥ó.
¥æ¡¼¥¶¤¬ºîÀ®¤·¤¿½é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Ï
ÂåÆþ¤Ê¤É¤ÎÌÀ¼¨Åª¤ÊÁàºî¤¬¹Ô¤ï¤ì¤ë¤Þ¤ÇÁ´¤Æ¥Ì¥ë¤Þ¤¿¤Ï 0 ¤È¤Ê¤ë¡£
¥³¥Þ¥ó¥É·²¤¬ÆþÎϹÔÁ´¤Æ¤Ë¤Ä¤¤¤Æ¼Â¹Ô¤µ¤ì¤ë sed ¤ä awk ¤È¤Ï°ã¤Ã¤Æ¡¢
¥³¥Þ¥ó¥É·²¤Ï°ìÅÙ¤·¤«¼Â¹Ô¤µ¤ì¤Ê¤¤¡£
¤³¤Î¤¿¤á¡¢ÆþÎÏ¥Õ¥¡¥¤¥ë¤Î³Æ¹Ô¤Ë¤Ä¤¤¤Æ·«¤êÊÖ¤·¤ò¹Ô¤¦¤Ë¤Ï
ÌÀ¼¨Åª¤Ë¥ë¡¼¥×¤òÀߤ±¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤°ìÊý¡¢
ÃåÌܤ¹¤ë¥Õ¥¡¥¤¥ë¡¢¹Ô¤ò¤è¤ê¤è¤¯¥³¥ó¥È¥í¡¼¥ë¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
(¼Â¤Ï¡¢Àµ¤·¤¯¤Ê¤¤... -n
¤ä -p
¥ª¥×¥·¥ç¥ó¤ò»È¤Ã¤Æ¡¢
¼«Æ°Åª¤Ë¥ë¡¼¥×¤µ¤»¤ë¤³¤È¤¬²Äǽ¤Ç¤¢¤ë¡£
See section ¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó.)
Àë¸Àʸ¤Ï¥³¥Þ¥ó¥É¤ò½ñ¤¯¤³¤È¤¬¤Ç¤¤ë¾ì½ê¤Ê¤é¤É¤³¤Ë¤Ç¤â½ñ¤¯¤³¤È¤¬¤Ç¤¡¢ ¥³¥Þ¥ó¥É¼Â¹Ô¤Î´ðËÜŪ¤Ê¥·¡¼¥±¥ó¥¹¤Ë¤Ï±Æ¶Á¤òÍ¿¤¨¤Ê¤¤¡£ ¤Ä¤Þ¤ê¡¢Àë¸À¤¬±Æ¶Á¤òÍ¿¤¨¤ë¤Î¤Ï¥³¥ó¥Ñ¥¤¥ë»þ¤À¤±¤Ç¤¢¤ë¡£ Ä̾ï¤ÏÁ´¤Æ¤ÎÀë¸À¤ò¥¹¥¯¥ê¥×¥È¤ÎºÇ½é¤«ºÇ¸å¤Î¤É¤Á¤é¤«¤Ë½ñ¤¯¡£
perl ¤Ï¡¢¤Û¤È¤ó¤É¡¢¥Õ¥ê¡¼¥Õ¥©¡¼¥à¤Î¸À¸ì¤Ç¤¢¤ë¡£ (Í£°ì¤ÎÎã³°¤Ï¥Õ¥©¡¼¥Þ¥Ã¥È¤ÎÀë¸À¤Ç¤¢¤ë¤¬¡¢¤½¤ÎÍýͳ¤ÏÌÀÇò¤Ç¤¢¤ë¡£)
¥³¥á¥ó¥È¤Ïʸ»ú #
¤«¤é¹Ô¤Î½ª¤ï¤ê¤Þ¤Ç¤Ç¤¢¤ë¡£
C ¤Î¥³¥á¥ó¥È /* */
¤ò»È¤¦¤È¡¢
¥³¥ó¥Æ¥¥¹¥È¤Ë¤è¤ê³ä¤ê»»¤â¤·¤¯¤Ï¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¥ó¥°¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¤ë¤Î¤Ç¡¢
ÍѤ¤¤Ê¤¤¤è¤¦¤Ë¡£
perl ¤Ë¤ª¤¤¤Æ¡¢¥³¥Þ¥ó¥É·²¤ò `{}' ¤Ç°Ï¤à¤È °ì¤Ä¤Î¥³¥Þ¥ó¥É¤È¤·¤Æ°·¤¦¤³¤È¤¬¤Ç¤¤ë¡£¤³¤ì¤ò¥Ö¥í¥Ã¥¯¤È¸Æ¤Ö¡£
¼¡¤ÎÊ£¹ç¥³¥Þ¥ó¥É¤Ï¥Õ¥í¡¼¥³¥ó¥È¥í¡¼¥ë¤Î¤¿¤á¤ËÍѤ¤¤ë¡£
if (EXPR) BLOCK if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK LABEL while (EXPR) BLOCK LABEL while (EXPR) BLOCK continue BLOCK LABEL for (EXPR; EXPR; EXPR) BLOCK LABEL foreach VAR (ARRAY) BLOCK LABEL BLOCK continue BLOCK
Ãí°Õ¤¹¤Ù¤¤³¤È¤Ï¡¢C ¤ä Pascal ¤È°ã¤¤¡¢¤³¤ì¤é¤Ïʸ(statement)¤Ç¤Ï¤Ê¤¯¡¢
¥Ö¥í¥Ã¥¯¤È¤·¤ÆÀë¸À¤µ¤ì¤Æ¤¤¤ëÅÀ¤Ç¤¢¤ë¡£¤³¤Î¤¿¤á¡¢{}
¤¬É¬ÍפȤʤ롣
¾ò·ïʸ¤ò {}
¤ò»È¤ï¤º¤Ë½ñ¤¯¤¿¤á¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«ÊýË¡¤¬¤¢¤ë¡£
¼¡¤ÎÎã¤ÏÁ´¤ÆƱ¤¸¤³¤È¤ò¤¹¤ë¡£
if (!open(foo)) { die "Can't open $foo: $!"; } die "Can't open $foo: $!" unless open(foo); open(foo) || die "Can't open $foo: $!"; # foo or bust! open(foo) ? 'hi mom' : die "Can't open $foo: $!"; # a bit exotic, that last one
if
ʸ¤Ïñ½ã¤Ç¤¢¤ë¡£¥Ö¥í¥Ã¥¯¤Ïɬ¤º {}
¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢
if
¤ä else
¤¬¤É¤³¤Ë¤«¤«¤ë¤«¤Ë¤Ä¤¤¤ÆÛ£Ëæ¤Ë¤Ê¤ë¤³¤È¤Ï¤Ê¤¤¡£
if
¤ÎÂå¤ï¤ê¤Ë unless
¤ò»È¤¦¾ì¹ç¡¢¥Æ¥¹¥È¤Î·ë²Ì¤¬µÕ¤Ë°·¤ï¤ì¤ë¡£
while
ʸ¤Ï expression ¤¬¿¿(¥Ì¥ëʸ»úÎó¤ä 0 ¤Ç¤Ê¤¤)¤Ç¤¢¤ë´Ö¡¢
¥Ö¥í¥Ã¥¯¤ò¼Â¹Ô¤¹¤ë¡£¥é¥Ù¥ë¤ò¤Ä¤±¤Æ¤â¤è¤¤¡£¥é¥Ù¥ë¤ò¤Ä¤±¤ë¾ì¹ç¡¢
¤½¤Î¼±Ê̻Ҥθå¤Ë¥³¥í¥ó¤ò¤Ä¤±¤ë¡£
¥é¥Ù¥ë¤Ï¥ë¡¼¥×¥³¥ó¥È¥í¡¼¥ëʸ next
¡¢last
¡¢redo
¤Î
¥ë¡¼¥×¤ò»ØÄꤹ¤ë(identifies the loop)(°Ê²¼¤ÎÎã¤ò»²¾È¡£)¡£
continue
¥Ö¥í¥Ã¥¯¤¬¤¢¤ì¤Ð¡¢¾ò·ïʸ¤òºÆɾ²Á¤¹¤ëľÁ°¤Ëɬ¤º¼Â¹Ô¤µ¤ì¤ë¡£
¤³¤ì¤Ï for
¥ë¡¼¥×¤Î 3 ÈÖÌܤξò·ï¤ÈƱÍͤǤ¢¤ë¡£
¤³¤Î¤¿¤á¡¢¤¿¤È¤¨¥ë¡¼¥×¤¬ next
ʸ¤òÄ̤¸¤Æ³¹Ô¤µ¤ì¤ë¾ì¹ç¤Ç¤â¡¢
¥ë¡¼¥×ÊÑ¿ô¤Î¥¤¥ó¥¯¥ê¥á¥ó¥È¤ò¹Ô¤¦¤¿¤á¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¡£
(C ¤Î continue ʸ¤ÈƱÍÍ¡£)
while
¤ò until
¤ÇÃÖ¤´¹¤¨¤ë¤È¡¢
¥Æ¥¹¥È¤Î·ë²Ì¤¬µÕ¤Ë°·¤ï¤ì¤ë¤¬¡¢¾ò·ï¥Æ¥¹¥È¤Ï¥ë¡¼¥×¤ÎºÇ½é¤Ë¤â¹Ô¤ï¤ì¤ë¡£
if
ʸ¤ä while
ʸ¤Ë¤ª¤¤¤Æ¡¢
(EXPR)
¤ò¥Ö¥í¥Ã¥¯¤ÇÃÖ¤´¹¤¨¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¤³¤Î¾ì¹ç¡¢¾ò·ï¤Ï¥Ö¥í¥Ã¥¯¤ÎºÇ¸å¤Î¥³¥Þ¥ó¥É¤ÎÃͤ¬¿¿¤Ê¤é¤Ð¿¿¤È¤Ê¤ë¡£
for
¥ë¡¼¥×¤Ï
¤½¤ì¤ÈÂбþ¤¹¤ë while
¥ë¡¼¥×¤ÈÁ´¤¯Æ±ÍͤËÆ°ºî¤¹¤ë¡£
for ($i = 1; $i < 10; $i++) { ... }
¤Ï¼¡¤ÈƱ¤¸¤Ç¤¢¤ë¡£
$i = 1; while ($i < 10) { ... } continue { $i++; }
foreach
¥ë¡¼¥×¤ÏÄ̾ï¤ÎÇÛÎóÃͤˤĤ¤¤Æ¡¢
½ç¤Ë¤½¤ÎÍ×ÁǤòÊÑ¿ô¤Ë¥»¥Ã¥È¤·¤Ê¤¬¤é·«¤êÊÖ¤·¤ò¹Ô¤¦¡£
ÊÑ¿ô¤Ï°ÅÌÛŪ¤Ë¥ë¡¼¥×¤Ë¥í¡¼¥«¥ë¤Ç¡¢¥ë¡¼¥×¤òÈ´¤±¤ë¤È¸µ¤ÎÃͤËÌá¤ë¡£
¼Â¤Ï¥¡¼¥ï¡¼¥É foreach
¤Ï for
¤ÈÁ´¤¯Æ±¤¸¤â¤Î¤Ê¤Î¤Ç¡¢
Æɤ߰פµ¤Ç foreach
¡¢´Ê·é¤µ¤Ç for
¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
ÊÑ¿ô̾¤ò¾Êά¤¹¤ë¤È¡¢³Æ¡¹¤ÎÃÍ¤Ï $_
¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£
ÇÛÎóÃͤ¬(ÇÛÎóÃͤòÊÖ¤¹ expression ¤Ç¤Ï¤Ê¤¯)¼ÂºÝ¤ÎÇÛÎó¤Î¾ì¹ç¤Ï¡¢
¥ë¡¼¥×¤ÎÃæ¤ÇÊÑ¿ô¤òÊѹ¹¤¹¤ë¤³¤È¤ÇÇÛÎóÍ×ÁǤòÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£Î㤨¤Ð:
for (@ary) { s/foo/bar/; } foreach $elem (@elements) { $elem *= 2; } for ((10,9,8,7,6,5,4,3,2,1,'BOOM')) { print $_, "\n"; sleep(1); } for (1..15) { print "Merry Christmas\n"; } foreach $item (split(/:[\\\n:]*/, $ENV{'TERMCAP'})) { print "Item: $item\n"; }
¥Ö¥í¥Ã¥¯¤Ï¤½¤ì¼«ÂÎ(¥é¥Ù¥ë¤¬¤Ä¤¤¤Æ¤¤¤Æ¤â¤¤¤Ê¤¯¤Æ¤â)¤¬
°ì²ó¤À¤±¼Â¹Ô¤µ¤ì¤ë¥ë¡¼¥×¤ÈƱ¤¸¤Ç¤¢¤ë¡£¤½¤³¤Ç¡¢¥Ö¥í¥Ã¥¯¤«¤éÈ´¤±¤¿¤ê¡¢
¥Ö¥í¥Ã¥¯¤òºÆ¼Â¹Ô¤·¤¿¤ê¤¹¤ë¤Î¤Ë¥ë¡¼¥×¥³¥ó¥È¥í¡¼¥ëʸ¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
continue
¥Ö¥í¥Ã¥¯¤â¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¤³¤Î¤è¤¦¤Ê¹½À®¤Ï case
¹½Â¤¤òµ½Ò¤¹¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
foo: { if (/^abc/) { $abc = 1; last foo; } if (/^def/) { $def = 1; last foo; } if (/^xyz/) { $xyz = 1; last foo; } $nothing = 1; }
ƱÍͤΤ³¤È¤òµ½Ò¤¹¤ëÊýË¡¤¬¤¤¤¯¤Ä¤«¤¢¤ë¤Î¤Ç¡¢
perl ¤Ë¤ÏÀµ¼°¤Ê switch
ʸ¤Ï¤Ê¤¤¡£¾å¤ÎÎã¤ËÉÕ¤±²Ã¤¨¤ë¤È¡¢
¼¡¤Î¤è¤¦¤Ë¤â½ñ¤±¤ë¡£
foo: { $abc = 1, last foo if /^abc/; $def = 1, last foo if /^def/; $xyz = 1, last foo if /^xyz/; $nothing = 1; }
¤Þ¤¿¤Ï
foo: { /^abc/ && do { $abc = 1; last foo; }; /^def/ && do { $def = 1; last foo; }; /^xyz/ && do { $xyz = 1; last foo; }; $nothing = 1; }
¤Þ¤¿¤Ï
foo: { /^abc/ && ($abc = 1, last foo); /^def/ && ($def = 1, last foo); /^xyz/ && ($xyz = 1, last foo); $nothing = 1; }
¤µ¤é¤Ë¤Ï
if (/^abc/) { $abc = 1; } elsif (/^def/) { $def = 1; } elsif (/^xyz/) { $xyz = 1; } else {$nothing = 1;}
¼ÂºÝ¤Ë¤Ï¤³¤ì¤é¤Ï¤¹¤Ù¤ÆÆâÉô¤Ç switch ¹½Â¤¤ËºÇŬ²½¤µ¤ì¤ë¤Î¤Ç¡¢
perl ¤ÏľÀÜÌÜŪ¤È¤¹¤ëʸ¤Ø¥¸¥ã¥ó¥×¤¹¤ë¡£
¤À¤«¤é°ì¤Ä¤ÎƱ¤¸Ã±½ã¤Ê¥¹¥«¥é¡¼Ãͤò ==
¤ä eq
¤ä
¾å¤Î¤è¤¦¤Ê¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¥ó¥°¤Ç¥Æ¥¹¥È¤¹¤ë¤«¤®¤ê¤Ë¤ª¤¤¤Æ¤Ï¡¢
elsif
¤¬ 50 ¤â¤¢¤Ã¤¿¤ê¤¹¤ë¤È¡¢
perl ¤¬ÉÔɬÍפÊʸ¤ò¤¿¤¯¤µ¤ó¼Â¹Ô¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¤¤«¡¢¤È¤¤¤¦¿´ÇÛ¤ò¤¹¤ëɬÍפϤʤ¤¡£
(¤â¤·¡¢case ¥¹¥Æ¡¼¥È¥á¥ó¥È¤ËºÇŬ²½¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ë¶½Ì£¤¬¤¢¤ë¤Ê¤é¡¢
-D1024
¤òÍѤ¤¤Æ¼Â¹ÔÁ°¤Ë¥·¥ó¥¿¥Ã¥¯¥¹¥Ä¥ê¡¼¤òɽ¼¨¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤ë¡£)
ñʸ¤Î¤ß¤¬¤½¤ÎÉûºîÍѤòɾ²Á¤µ¤ì¤ë expression ¤Ç¤¢¤ë¡£ ñʸ¤Ï¡¢¥Ö¥í¥Ã¥¯¤ÎºÇ¸å¤Îʸ¤ò½ü¤¤¤Æ¡¢ ¤¹¤Ù¤Æ¥»¥ß¥³¥í¥ó¤Ç½ª¤ï¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ ¥Ö¥í¥Ã¥¯¤ÎºÇ¸å¤Îʸ¤Ç¤Ï¥»¥ß¥³¥í¥ó¤Ï¤¢¤Ã¤Æ¤â¤Ê¤¯¤Æ¤â¤è¤¤¡£ (¤·¤«¤·¡¢ ¥Ö¥í¥Ã¥¯¤¬ 2 ¹Ô°Ê¾å¤«¤é¤Ê¤ë¾ì¹ç¤Ë¤Ï¤ä¤Ï¤ê¥»¥ß¥³¥í¥ó¤ò¤Ä¤±¤ë¤³¤È¤¬Ë¾¤Þ¤·¤¤¡£)
ñʸ¤ÏÁ´¤Æ½¤¾þ»Ò¤ò°ì¤Ä¡¢½ªÎ»¤ò¼¨¤¹¥»¥ß¥³¥í¥ó¤ÎľÁ°¤Ë¤Ä¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£ °Ê²¼¤Î¤â¤Î¤¬½¤¾þ»Ò¤È¤·¤Æ»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
if EXPR unless EXPR while EXPR until EXPR
if
¤ä unless
½¤¾þ»Ò¤Ï¸«³Ý¤±Ä̤ê¤Î°ÕÌ£¤ò»ý¤Ä¡£
while
¤ä until
½¤¾þ»Ò¤â¤Þ¤¿¸«³Ý¤±Ä̤ê¤Î°ÕÌ£¤ò¤â¤Ä
(¾ò·ï¤ÏºÇ½é¤Ëɾ²Á¤µ¤ì¤ë)¤¬¡¢
do-¥Ö¥í¥Ã¥¯ ¤Þ¤¿¤Ï do-¥µ¥Ö¥ë¡¼¥Á¥ó ¥³¥Þ¥ó¥É¤ËŬÍѤµ¤ì¤¿¾ì¹ç¤Ï°Û¤Ê¤ë¡£
¤³¤Î¾ì¹ç¡¢¾ò·ïʸ¤òɾ²Á¤¹¤ëÁ°¤Ë¥Ö¥í¥Ã¥¯¤ò°ì²ó¼Â¹Ô¤¹¤ë¡£
¤³¤ì¤Ï¼¡¤Î¤è¤¦¤Ê¥ë¡¼¥×¤ò½ñ¤¯¤³¤È¤ò²Äǽ¤Ë¤¹¤ë¤¿¤á¤Ç¤¢¤ë¡£
do { $_ = <STDIN>; ... } until $_ eq ".\n";
(do
±é»»»Ò¤Î¹à¤ò»²¾È¡£¤Þ¤¿¡¢¤³¤Î¾ì¹ç¤Ï¡¢
¥ë¡¼¥×¥³¥ó¥È¥í¡¼¥ë¥³¥Þ¥ó¥É¤Ï»È¤¨¤Ê¤¤¡£¤Ê¤¼¤Ê¤é¡¢
½¤¾þ»Ò¤Ï¥ë¡¼¥×¥é¥Ù¥ë¤ò»ý¤Ä¤³¤È¤¬¤Ç¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£¤¢¤·¤«¤é¤º¡£)See section do.
==
¤Ï¿ôÃͤÎƱÃÍÀ)¡£
(¤â¤·¡¢¾õ¶·¤Ë±þ¤¸¤Æ ==
¤¬
ʸ»úÎ󤪤è¤Ó¿ôÃͤÎξÊý¤ÎƱÃÍÀ¤òɽ¤¹ awk ¤Ë´·¤ì¤Æ¤¤¤ë¤Ê¤é¡¢Ãí°Õ¤»¤è!)!=
¤Ï¿ôÃͤÎÈóƱÃÍÀ)¡£
$_
¤ËÂФ·¤Æ¹Ô¤¦¤â¤Î¤¬¤¢¤ë¡£
=~
±é»»»Ò¤òÍѤ¤¤ë¤È¡¢Ê̤Îʸ»úÎó¤ËÂФ·¤Æ¤½¤Î±é»»¤¬¹Ô¤ï¤ì¤ë¡£
±¦¤Î°ú¿ô¤Ï¸¡º÷¥Ñ¥¿¡¼¥ó¡¦ÃÖ´¹¡¦ÊÑ´¹(translation) ¤Ç¤¢¤ê¡¢
º¸¤Î°ú¿ô¤Ï¥Ç¥Õ¥©¥ë¥È¤Î $_
¤ÎÂå¤ï¤ê¤Ë
¸¡º÷¡¦ÃÖ´¹¡¦ÊÑ´¹¤ÎÂоݤȤʤëʸ»úÎó¤Ç¤¢¤ë¡£ÊÖ¤êÃͤϱ黻¤ÎÀ®ÈݤòÊÖ¤¹¡£
(±¦°ú¿ô¤¬¸¡º÷¥Ñ¥¿¡¼¥ó¡¦ÃÖ´¹¡¦ÊÑ´¹ ¤Ç¤Ï¤Ê¤¯¤Æ¤¢¤ë expression ¤Ç¤¢¤ë¾ì¹ç¤Ï¡¢
¼Â¹Ô»þ¤Ë¸¡º÷¥Ñ¥¿¡¼¥ó¤È¤·¤Æ²ò¼á¤µ¤ì¤ë¡£
¤½¤Î expression ¤¬É¾²Á¤µ¤ì¤ëÅ٤˥ѥ¿¡¼¥ó¤¬¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë¤Î¤Ç¡¢
¤³¤ì¤Ï¥Ñ¥¿¡¼¥ó¤òÌÀ¼¨¤·¤¿¸¡º÷¤ËÈæ¤Ù¤ÆÈó¸úΨŪ¤Ç¤¢¤ë¡£)
¤³¤Î±é»»»Ò¤Ï -
(ñ¹à¥Þ¥¤¥Ê¥¹±é»»»Ò)¡¢++
¡¢--
¤ò½ü¤¯
¾¤Î±é»»¤è¤ê¤âÍ¥ÀèÅÙ¤¬¹â¤¤¡£
=~
¤ÈƱ¤¸¤Ç¤¢¤ë¡£
print '-' x 80; # ¥À¥Ã¥·¥å¤ÎÎó¤ò½ÐÎϤ¹¤ë print '-' x80; # Àµ¤·¤¯¤Ê¤¤¡¢¤Ê¤¼¤Ê¤é x80 ¤Ï¼±Ê̻ҤÀ¤«¤é print "\t" x ($tab/8), ' ' x ($tab%8); # ¥¿¥Ö¤ËÊÑ´¹ @ones = (1) x 80; # 80 ¸Ä 1 ¤¬Ê¤ó¤ÀÇÛÎó @ones = (5) x @ones; # Á´Í×ÁǤò 5 ¤Ë¤¹¤ë
for (1..10)
¥ë¡¼¥×¤äÇÛÎó¤Î°ìÉô¤òÀÚ¤ê½Ð¤¹Áàºî¤Ë¤ÏÊØÍø¤Ç¤¢¤ë¡£
¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï ..
¤ÏÏÀÍýÃͤòÊÖ¤¹¡£
±é»»»Ò¤Ï¥Õ¥ê¥Ã¥×¥Õ¥í¥Ã¥×¤Î¤è¤¦¤Ë 2 Ä̤ê¤ÎÃͤò¤È¤ê¡¢sed, awk,
¤½¤·¤Æ¤¤¤í¤¤¤í¤Ê¥¨¥Ç¥£¥¿¤Î¹ÔÈÏ°Ï(¥³¥ó¥Þ)±é»»»Ò¤ò¥¨¥ß¥å¥ì¡¼¥È¤¹¤ë¡£
..
¤Ï¤½¤ì¤¾¤ì¤¬¼«Ê¬¤À¤±¤ÎÏÀÍý¾õÂÖ¤ò»ý¤Ã¤Æ¤¤¤Æ¡¢º¸°ú¿ô¤¬µ¶¤Ç¤¢¤ë¸Â¤ê¡¢
µ¶¤ÎÃͤò»ý¤Ä¡£¤¤¤Ã¤¿¤óº¸°ú¿ô¤¬¿¿¤Ë¤Ê¤ë¤È¡¢±¦°ú¿ô¤¬¿¿¤Ë¤Ê¤ë¤Þ¤Ç¿¿¤Ç¤¢¤ë¡£
¤½¤Î¸å¡¢ÈÏ°Ï»ØÄê±é»»»Ò¤ÏºÆ¤Óµ¶¤Ë¤Ê¤ë¡£
(..
¤Ï¼¡¤Ëɾ²Á¤µ¤ì¤ë¤Þ¤Ç¡¢µ¶¤Ë¤Ï¤Ê¤é¤Ê¤¤¡£
(º¸°ú¿ô¤Î¥Æ¥¹¥È¤Î·ë²Ì[ÌõÊäÂ])¿¿¤Ë¤Ê¤Ã¤¿É¾²Á¤Ë¤ª¤¤¤Æ¡¢
±¦°ú¿ô¤ò¥Æ¥¹¥È¤·¤¿·ë²Ìµ¶¤Ë¤Ê¤ë¤³¤È¤¬¤¢¤ê¤¦¤ë(awk ¤Î¤è¤¦¤Ë)¤¬¡¢
¤½¤ì¤Ç¤â°ìÅ٤Ͽ¿¤òÊÖ¤¹¡£
(sed ¤Î¤è¤¦¤Ë)¼¡¤Ëɾ²Á¤¹¤ë¤Þ¤Ç±¦°ú¿ô¤Î¥Æ¥¹¥È¤ò¤·¤¿¤¯¤Ê¤¤¾ì¹ç¤Ë¤Ï
¥É¥Ã¥È 2 ¤Ä¤ÎÂå¤ï¤ê¤Ë 3 ¤Ä(...
)¤ò»È¤¨¤Ð¤è¤¤¡£)
±é»»»Ò¤¬µ¶¤Î´Ö¤Ï±¦°ú¿ô¤Ïɾ²Á¤µ¤ì¤º¡¢
±é»»»Ò¤¬¿¿¤Î´Ö¤Ïº¸°ú¿ô¤Ïɾ²Á¤µ¤ì¤Ê¤¤¡£
Í¥ÀèÅÙ¤Ï ||
¤ä &&
¤è¤ê¤â¾¯¤·Ä㤤¡£ÊÖ¤êÃͤϵ¶¤Ê¤é¤Ð¥Ì¥ëʸ»úÎó¡¢
¿¿¤Ê¤é¤Ð(1 ¤«¤é»Ï¤Þ¤ë)Ϣ³¤·¤¿¿ô»ú¤Ç¤¢¤ë¡£
¤³¤Î¿ô»ú¤ÏÈÏ°Ï»ØÄê¤Ë½Ð²ñ¤¦Ëè¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
ÈϰϤκǸå¤Î¿ô»ú¤Ë¤Ïʸ»úÎó `E0' ¤¬¤Ä¤±¤é¤ì¤ë¤Î¤Ç¡¢¿ôÃͤ˱ƶÁ¤Ï¤Ê¤¤¤¬¡¢
ºÇ¸å¤ÎÅÀ¤ò½ü¤¤¿¤¤¾ì¹ç¤Ë¸¡º÷¤Î¤¤Ã¤«¤±¤È¤Ê¤ë¡£
¿ô»ú¤¬ 1 ¤è¤êÂ礤¯¤Ê¤ë¤Î¤òÂԤĤ³¤È¤ÇºÇ½é¤ÎÅÀ¤ò½ü¤¯¤³¤È¤¬¤Ç¤¤ë¡£
¥¹¥«¥é¡¼¤Î ..
¤Î°ú¿ô¤Î¤É¤Á¤é¤«¤ÎÃͤ¬ÀÅŪ¤Ê¾ì¹ç¤Ï¡¢
°ú¿ô¤Ï°ÅÌۤΤ¦¤Á¤ËÊÑ¿ô $.
¤ÈÈæ³Ó¤µ¤ì¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$.@hfil} : ºÇ¸å¤ËÆɤ߹þ¤ß¤ò¹Ô¤Ã¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¸½ºß¤Î¹ÔÈÖ¹æ}.
¥¹¥«¥é¡¼±é»»»Ò¤È¤·¤Æ¤Ï :
if (101 .. 200) { print; } # 200 ¹Ô½ÐÎϤ¹¤ë next line if (1 .. /^$/); # ¥Ø¥Ã¥À¡¼¹Ô¤ò¥¹¥¥Ã¥× s/^/> / if (/^$/ .. eof()); # ËÜÂΤò°úÍѤ¹¤ëÇÛÎó±é»»»Ò¤È¤·¤Æ¤Ï:
for (101 .. 200) { print; } # $_ ¤ò 100 ²ó½ÐÎϤ¹¤ë @foo = @foo[$[ .. $#foo]; # ¹â²Á¤Ê¥Î¡¼¥ª¥Ú¥ì¡¼¥·¥ç¥ó @foo = @foo[$#foo-4 .. $#foo]; # ºÇ¸å¤Î 5 Í×ÁǤò¼è¤ê½Ð¤¹
¤³¤Î±é»»»Ò¤Ï¥Õ¥¡¥¤¥ë̾¤«¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò°ú¿ô¤È¤·¤Æ°ì¤Ä¤È¤ê¡¢
¤½¤Î¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ²¿¤«¤¬¿¿¤«¤É¤¦¤«¤ò¸«¤ë¡£
°ú¿ô¤ò¾Êά¤¹¤ë¤È¡¢$_
¤ò¥Æ¥¹¥È¤¹¤ë¡£
Îã³°¤Ï -t
¤Ç¡¢STDIN
¤ò¥Æ¥¹¥È¤¹¤ë¡£
¿¿¤Î¾ì¹ç¤Ï 1¡¢µ¶¤Î¾ì¹ç¤Ï "
¤«¡¢
¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï undefined value ¤òÊÖ¤¹¡£
Í¥ÀèÅÙ¤ÏÏÀÍý±é»»»Ò¡¢´Ø·¸±é»»»Ò¤è¤ê¤â¹â¤¤¤¬¡¢¿ô³Ø±é»»»Ò¤è¤ê¤ÏÄ㤤¡£
±é»»»Ò¤Î¼ïÎà¤Ï¡¢°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
-r ¥Õ¥¡¥¤¥ë¤ò¼Â¸ú uid/gid ¤ÇÆɤळ¤È¤¬¤Ç¤¤ë¡£ -w ¥Õ¥¡¥¤¥ë¤Ë¼Â¸ú uid/gid ¤Ç½ñ¤¯¤³¤È¤¬¤Ç¤¤ë¡£ -x ¥Õ¥¡¥¤¥ë¤ò¼Â¸ú uid/gid ¤Ç¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£ -o ¥Õ¥¡¥¤¥ë¤Î½êͼԤ¬¼Â¸ú uid ¤Ç¤¢¤ë¡£ -R ¥Õ¥¡¥¤¥ë¤ò¼Â uid/gid ¤ÇÆɤळ¤È¤¬¤Ç¤¤ë¡£ -W ¥Õ¥¡¥¤¥ë¤Ë¼Â uid/gid ¤Ç½ñ¤¯¤³¤È¤¬¤Ç¤¤ë¡£ -X ¥Õ¥¡¥¤¥ë¤ò¼Â uid/gid ¤Ç¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£ -O ¥Õ¥¡¥¤¥ë¤Î½êͼԤ¬¼Â uid ¤Ç¤¢¤ë¡£ -e ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¡£ -z ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤¬ 0 ¤Ç¤¢¤ë¡£ -s ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤¬ 0 ¤Ç¤Ê¤¤(¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤òÊÖ¤¹)¡£ -f ¥Õ¥¡¥¤¥ë¤Ï¥×¥ì¡¼¥ó¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£ -d ¥Õ¥¡¥¤¥ë¤Ï¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë¡£ -l ¥Õ¥¡¥¤¥ë¤Ï¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç¤¢¤ë¡£ -p ¥Õ¥¡¥¤¥ë¤Ï̾Á°¤Ä¤¥Ñ¥¤¥×(FIFO)¤Ç¤¢¤ë¡£ -S ¥Õ¥¡¥¤¥ë¤Ï¥½¥±¥Ã¥È¤Ç¤¢¤ë¡£ -b ¥Õ¥¡¥¤¥ë¤Ï¥Ö¥í¥Ã¥¯Æüì¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£ -c ¥Õ¥¡¥¤¥ë¤Ï¥¥ã¥é¥¯¥¿¡¼Æüì¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£ -u ¥Õ¥¡¥¤¥ë¤Ë setuid ¥Ó¥Ã¥È¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¡£ -g ¥Õ¥¡¥¤¥ë¤Ë setgid ¥Ó¥Ã¥È¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¡£ -k ¥Õ¥¡¥¤¥ë¤Ë sticky ¥Ó¥Ã¥È¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¡£ -t ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ tty ¤Ë¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£ -T ¥Õ¥¡¥¤¥ë¤Ï¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£ -B ¥Õ¥¡¥¤¥ë¤Ï¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£(-T ¤ÎµÕ) -M ¥¹¥¯¥ê¥×¥È¤Î¼Â¹Ô¤ò³«»Ï¤·¤¿»þÅÀ¤Ç¤Î¥Õ¥¡¥¤¥ë¤Î¸Å¤µ(age)(ñ°Ì¤ÏÆü) -A ¥¹¥¯¥ê¥×¥È¤Î¼Â¹Ô¤ò³«»Ï¤·¤¿»þÅÀ¤Ç¤Î¥Õ¥¡¥¤¥ë¤Î¥¢¥¯¥»¥¹»þ´Ö -C ¥¹¥¯¥ê¥×¥È¤Î¼Â¹Ô¤ò³«»Ï¤·¤¿»þÅÀ¤Ç¤Î¥Õ¥¡¥¤¥ë¤Î inode Êѹ¹»þ´Ö
±é»»»Ò -r
,-R
,-w
,-W
,-x
,-X
¤ÎȽÃǤϡ¢
¥Õ¥¡¥¤¥ë¤Î¥â¡¼¥É¤È¥æ¡¼¥¶¤Î uid¡¢gid ¤Î¤ß¤Ë¤è¤ë¡£
¼ÂºÝ¤ËÆɤß/½ñ¤/¼Â¹Ô¤Ç¤¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
¤Þ¤¿¡¢¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Î¾ì¹ç¤Ï¡¢
-r
,-R
,-w
,-W
¤Ï¾ï¤Ë 1 ¤òÊÖ¤·¡¢
-x
,-X
¤Ë¤Ä¤¤¤Æ¤Ï
¥Õ¥¡¥¤¥ë¥â¡¼¥É¤Ë¤¤¤º¤ì¤«¤Î¼Â¹Ôµö²Ä¤¬¤Ä¤¤¤Æ¤¤¤ì¤Ð 1 ¤òÊÖ¤¹¡£
¤³¤Î¤¿¤á¡¢¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤¬¼Â¹Ô¤¹¤ë¥¹¥¯¥ê¥×¥È¤Ë¤ª¤¤¤Æ
¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¥â¡¼¥É¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¡¢stat()
¤ò¹Ô¤¦¤«¡¢
°ì»þŪ¤Ë uid ¤ò¾¤Î¤â¤Î¤Ë¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ë¡£
while (<>) { chop; next unless -f $_; # Æüì¥Õ¥¡¥¤¥ë¤Ï̵»ë¤¹¤ë ... }
(Ãí°Õ)
-s/a/b/
¤È¤·¤Æ¤â¡¢ÃÖ´¹¤Î¥Þ¥¤¥Ê¥¹¤ò¤È¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
-exp($foo)
¤Ï´üÂÔÄ̤ê¤ËÆ°¤¯¡£¤·¤«¤·¡¢
¥Þ¥¤¥Ê¥¹¤Î¸å¤Ë 1 ʸ»ú¤·¤«¤Ê¤±¤ì¤Ð¡¢¥Õ¥¡¥¤¥ë¥Æ¥¹¥È¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¤ë¡£
-T
¤ª¤è¤Ó -B
¤Ï¼¡¤Î¤è¤¦¤ËÆ°ºî¤¹¤ë¡£
¥Õ¥¡¥¤¥ë¤ÎºÇ½é¤Î¥Ö¥í¥Ã¥¯¤Ë¤Ä¤¤¤Æ¡¢¤¢¤Þ¤ê½Ð¤Æ¤³¤Ê¤¤Ê¸»ú
(´ñ̯¤Ê¥³¥ó¥È¥í¡¼¥ë¥³¡¼¥É¡¢¥á¥¿¥¥ã¥é¥¯¥¿¡¼)¤¬¤¢¤ë¤«¤É¤¦¤«¸¡ºº¤¹¤ë¡£
¤â¤·¤½¤ì¤¬Â¿¤±¤ì¤Ð(>10%)¡¢¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤Ç¤¢¤ê¡¢
¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£
¤Þ¤¿¡¢ºÇ½é¤Î¥Ö¥í¥Ã¥¯¤Ë¥Ì¥ë¤ò´Þ¤à¥Õ¥¡¥¤¥ë¤â¥Ð¥¤¥Ê¥ê¤È¤µ¤ì¤ë¡£
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ËÂФ·¤Æ -T
¤ä -B
¤ò»È¤¦¤È¡¢
ºÇ½é¤Î¥Ö¥í¥Ã¥¯¤ÎÂؤï¤ê¤Ë¸½ºß¤Îɸ½àÆþÎϥХåե¡¤¬ÍѤ¤¤é¤ì¤ë¡£
¥Ì¥ë¥Õ¥¡¥¤¥ë¤ä¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò¥Æ¥¹¥È¤¹¤ë»þ¤Ë¥Õ¥¡¥¤¥ë¤¬ EOF ¤Ç¤¢¤ë¤È¡¢
-T
¤â -B
¤â¿¿¤òÊÖ¤¹¡£
¥Õ¥¡¥¤¥ë¥Æ¥¹¥È¤Ë¤ª¤¤¤Æ `_'(²¼Àþ)¤À¤±¤«¤é¤Ê¤ë
Æüì¤Ê¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò»ØÄꤹ¤ë¤È¡¢
Á°²ó¤Î¥Õ¥¡¥¤¥ë¥Æ¥¹¥È(¤Þ¤¿¤Ï stat()
)¤Ç¤Î stat
¹½Â¤ÂΤ¬ÍѤ¤¤é¤ì¡¢
¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¹Ô¤ï¤Ê¤¤¡£
(-t
¤Ï½ü¤¯¡£¤Þ¤¿¡¢lstat()
¤ä -l
¤Ï
¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¤Ç¤Ï¤Ê¤¯¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Î¾ðÊó¤ò stat
¹½Â¤ÂΤ˻Ĥ¹¤³¤È¤ò
³Ð¤¨¤Æ¤ª¤¯É¬Íפ¬¤¢¤ë¡£)
print "Can do.\n" if -r $a || -w _ || -x _; stat($filename); print "Readable\n" if -r _; print "Writable\n" if -w _; print "Executable\n" if -x _; print "Setuid\n" if -u _; print "Setgid\n" if -g _; print "Sticky\n" if -k _; print "Text\n" if -T _; print "Binary\n" if -B _;
perl ¤Ë¤Ê¤¯¤Æ C ¤Ë¤À¤±¤¢¤ë±é»»»Ò¤Ï°Ê²¼¤ÎÄ̤ꡣ
perl ¤Ï C ¤ÈƱ¤¸¤¯¡¢±é»»»Ò¤ËÂФ¹¤ë°ú¿ô¤¬Á´¤ÆÀÅŪ¤Ç¤¢¤ê¡¢ ÉûºîÍѤâ¤Ê¤¤¤ÈȽÃǤ·¤¿»þ¤Ï expression ¤Îɾ²Á¤ò¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¹Ô¤¦ (Æäˡ¢¥³¥ó¥Ñ¥¤¥ë»þ¤ËÊÑ¿ôÃÖ´¹¤ò¹Ô¤ï¤Ê¤¤Ê¸»úÎó´Ö¤Î·ë¹ç¤òȯ¸«¤·¤¿¾ì¹ç)¡£ ¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤Î²ò¼á¤â¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¹Ô¤ï¤ì¤ë¡£
'Now is the time for all' . "\n" . 'good men to come to.'
¤³¤ì¤Ï°ì¤Ä¤Îʸ»úÎó¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¡£
++
±é»»»Ò¤Ë¤Ï¤Á¤ç¤Ã¤È¤·¤¿ºÙ¹©¤ò¤·¤Æ¤¤¤ë¡£
¿ô»ú¤ä¡¢¿ôÃͤΥ³¥ó¥Æ¥¥¹¥È¤Ç»È¤Ã¤¿ÊÑ¿ô¤ò¥¤¥ó¥¯¥ê¥á¥ó¥È¤¹¤ë¤È¡¢
Ä̾ï¤Î¥¤¥ó¥¯¥ê¥á¥ó¥È¤ò¹Ô¤¦¡£
¤·¤«¤·¡¢¥»¥Ã¥È¤·¤Æ¤«¤éʸ»úÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤·¤«»È¤Ã¤Æ¤ª¤é¤º¡¢
¥Ì¥ë¤Ç¤Ê¤¤Ãͤò»ý¤Ã¤Æ¤¤¤Æ¡¢
¥Ñ¥¿¡¼¥ó /^[a-zA-Z]*[0-9]*$/
¤Ë¥Þ¥Ã¥Á¤¹¤ë¤è¤¦¤ÊÊÑ¿ô¤Î¾ì¹ç¡¢
ʸ»úÎó¤È¤·¤Æ¤Î¥¤¥ó¥¯¥ê¥á¥ó¥È¤òʸ»úÎó¤ÎÈϰϤϤ½¤Î¤Þ¤Þ¡¢
¥¥ã¥ê¡¼ÉÕ¤¤Ç¹Ô¤¦¡£
print ++($foo = '99'); # prints '100' print ++($foo = 'a0'); # prints 'a1' print ++($foo = 'Az'); # prints 'Ba' print ++($foo = 'zz'); # prints 'aaa'
--
±é»»»Ò¤Ë¤Ï¤³¤Î¤è¤¦¤ÊºÙ¹©¤Ï¤Ê¤¤¡£
(ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ë¤ª¤±¤ë)Èϰϱ黻»Ò¤Ï¡¢
ºÇ¾®ÃͤȺÇÂçÃͤ¬Ê¸»úÎó¤Î¾ì¹ç¤Ï ++
±é»»»Ò¤ÎºÙ¹©¤òÍøÍѤ·¤Æ¤¤¤ë¡£
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥Èʸ»ú¤ÎÁ´¤Æ¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¼¡¤Î¤è¤¦¤Ëµ½Ò¤Ç¤¤ë¡£
@alphabet = ('A' .. 'Z');
¤Þ¤¿¡¢16 ¿Ê¤ÎÃͤòÆÀ¤ë¤¿¤á¤Ë¤Ï¡¢
$hexdigit = (0 .. 9, 'a' .. 'f')[$num & 15];
¤½¤·¤Æ¡¢ºÇ½é¤Ë 0 ¤¬¤Ä¤¤¤¿ÆüÉÕ¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¡¢
@z2 = ('01' .. '31'); print @z2[$mday];
¤È½ñ¤±¤ë¡£
(»ØÄꤷ¤¿ºÇ½ªÃͤ¬ ++
¤ÎºÙ¹©¤¬½èÍý¤¹¤ë½çÈ֤ˤʤäƤ¤¤Ê¤¤¾ì¹ç¤Ï¡¢
¼¡¤ÎÃͤ¬»ØÄꤷ¤¿ºÇ½ªÃͤè¤êŤ¯¤Ê¤ë¤Þ¤Ç·«¤êÊÖ¤µ¤ì¤ë¡£)
||
¤ä &&
¤Ï C ¤Î¤½¤ì¤È¤Ï°Û¤Ê¤ê¡¢
0 ¤ä 1 ¤òÊÖ¤¹Âå¤ï¤ê¤ËºÇ¸å¤Ëɾ²Á¤·¤¿ÃͤòÊÖ¤¹¡£¤³¤Î¤¿¤á¡¢
¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê¤òõ¤¹¤¿¤á¤Î°Ü¿¢À¤Î¹â¤¤ÊýË¡¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ë¡£
$home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die "You're homeless!\n";
Á°¾Ï¤Þ¤Ç¤Ë½Ò¤Ù¤¿Ê¸»ú¤äÊÑ¿ô¤ÈƱ¤¸¤¯¡¢ ¼¡¾Ï°Ê¹ß¤Ç½Ò¤Ù¤ë±é»»»Ò¤Ï expression Ãæ¤Î"¸ì"¤È¤·¤Æµ¡Ç½¤¹¤ë¡£ ±é»»»Ò¤ÎÃæ¤Ë¤Ï¥ê¥¹¥È¤ò°ú¿ô¤Ë¼è¤ë¤â¤Î¤¬¤¢¤ë¡£ ¤³¤Î¥ê¥¹¥È¤Ï¥¹¥«¥é¡¼¤Î°ú¿ô¤äÇÛÎóÃͤ¬Ç¤°Õ¤Ë·ë¹ç¤µ¤ì¤¿¤â¤Î¤Ç¤¢¤ë¡£ ÇÛÎóÃͤϡ¢ ¥ê¥¹¥È¤Î¤½¤Î°ÌÃ֤˸ġ¹¤ÎÍ×ÁǤò½ñ¤¤¤Æ 1 ¼¡¸µ¤ÎÇÛÎóÃͤò¤¿¤¯¤µ¤óÀ¸À®¤·¤¿¤è¤¦¤Ê·Á¤Ç ¥ê¥¹¥È¤ËµÛ¼ý¤µ¤ì¤ë¡£
¥ê¥¹¥È¤ÎÍ×ÁǤϥ³¥ó¥Þ¤Ç¶èÀÚ¤ëɬÍפ¬¤¢¤ë¡£
±é»»»Ò¤ò¥ê¥¹¥È¤¹¤ë¤È¡¢°ú¿ô¤ÎÁ°¸å¤Ë³ç¸Ì¤¬¤¢¤ë¾ì¹ç¤Ê¤¤¾ì¹ç¶¦¤Ë¡¢ ¤½¤Î±é»»»Ò¤òñ¹à±é»»»Ò¤Þ¤¿¤Ï´Ø¿ô¸Æ¤Ó½Ð¤·¤È¤·¤Æ»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
´Ø¿ô¸Æ¤Ó½Ð¤·¤È¤·¤Æ»È¤¦¾ì¹ç¤Ï¡¢ Ʊ¤¸¹Ô¤Î¼¡¤Î¥È¡¼¥¯¥ó¤Ïº¸³ç¸Ì¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤(´Ö¤Ë¥¹¥Ú¡¼¥¹¤¬¤¢¤Ã¤Æ¤â¤è¤¤)¡£ ¤³¤Î¤è¤¦¤Ê´Ø¿ô¤Ï´üÂÔÄ̤ê¤ÎºÇ¤â¹â¤¤Í¥ÀèÅÙ¤ò»ý¤Ä¡£
º¸³ç¸Ì°Ê³°¤Î¥È¡¼¥¯¥ó¤¬Â³¤¯¾ì¹ç¤Ï¡¢Ã±¹à±é»»»Ò¤È¤·¤Æ°·¤ï¤ì¡¢ ¥ê¥¹¥È¤ò°ú¿ô¤Ë¼è¤ë±é»»»Ò¤«¤½¤¦¤Ç¤Ê¤¤¤«¤Î¤ß¤Ë¤è¤êÍ¥ÀèÅÙ¤¬·è¤Þ¤ë¡£ ¥ê¥¹¥È¤ò°ú¿ô¤Ë¼è¤ë¾ì¹ç¤ÏºÇ¤âÄ㤤ͥÀèÅ٤ˤʤ롣 ¾¤ÎÁ´¤Æ¤Îñ¹à±é»»»Ò¤Ï´Ø·¸±é»»»Ò¤è¤ê¤Ï¹â¤¤¤¬¿ôÃͱ黻»Ò¤è¤ê¤ÏÄ㤤ͥÀèÅ٤ˤʤ롣 Í¥ÀèÅ٤ξϤò»²¾È¤Î¤³¤È¡£See section Í¥ÀèÅÙ.
¥¹¥«¥é¡¼¡¢ÇÛÎó¤Îξ¥³¥ó¥Æ¥¥¹¥È¤Ç»ÈÍѤǤ¤ë±é»»»Ò¤Ï¡¢°ìÈÌŪ¤Ë¥¹¥«¥é¡¼¥³ ¥ó¥Æ¥¥¹¥È¤Ç¤Ï undefined value¡¢ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¥Ì¥ë¥ê¥¹¥È¤òÊÖ¤¹¤³ ¤È¤ÇÉÔÀ®¸ù¤ò¼¨¤¹¡£¤·¤«¤·¡¢¥ê¥¹¥È¤ò¥¹¥«¥é¡¼¤ØÊÑ´¹¤¹¤ë°ìÈÌŪ¤Ê¥ë¡¼¥ë ¤Ï¤Ê¤¤¤È¤¤¤¦¤³¤È¤ò³Ð¤¨¤Æ¤ª¤¤¤ÆÍߤ·¤¤¡£¤½¤ì¤¾¤ì¤Î±é»»»Ò¤Ï¡¢¤É¤Î¤è¤¦¤Ê¥¹ ¥«¥é¡¼¤òÊÖ¤»¤ÐºÇ¤âŬÀÚ¤«¤ò·èÄꤹ¤ë¡£ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤ÇÊÖ¤·¤¿¤Ç¤¢¤í¤¦¥ê ¥¹¥È¤ÎŤµ¤òÊÖ¤¹±é»»»Ò¡¢¥ê¥¹¥È¤ÎºÇ½é¤ÎÍ×ÁǤòÊÖ¤¹±é»»»Ò¡¢¥ê¥¹¥È¤ÎºÇ¸å¤ÎÍ× ÁǤòÊÖ¤¹±é»»»Ò¡¢À®¸ù¤·¤¿Áàºî¤Î¿ô¤òÊÖ¤¹±é»»»Ò¡¢¤Ê¤É¤¬¤¢¤ë¡£Áí¤¸¤Æ¡¢¤³¤ì¤é ¤Î±é»»»Ò¤Ï¤¢¤Ê¤¿¤¬µá¤á¤ë¤³¤È¤ò¤·¤Æ¤¯¤ì¤ë¡£°ì´ÓÀ¤òµá¤á¤Ê¤¤¤«¤®¤ê¡£
sub
¤ÇÀë¸À¤µ¤ì¤¿ SUBROUTINE ¤ò¼Â¹Ô¤·¡¢
SUBROUTINE ¤Çɾ²Á¤µ¤ì¤¿ºÇ¸å¤Î expression ¤ÎÃͤòÊÖ¤¹¡£
¤½¤Î̾Á°¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤¬¤Ê¤¤¾ì¹ç¤Ï¡¢Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë
(¥µ¥Ö¥ë¡¼¥Á¥ó¤¬Â¸ºß¤¹¤ë¤«¤É¤¦¤«ÃΤë¤Ë¤Ï¡¢
defined
±é»»»Ò¤ò»ÈÍѤ¹¤ì¤ÐÎɤ¤¡£)¡£
LIST ¤Î°ìÉô¤È¤·¤ÆÇÛÎó¤òÅϤ¹¾ì¹ç¡¢
³ÆÇÛÎó¤ÎÁ°¤ËÇÛÎó¤ÎŤµ¤òÅϤ·¤Æ¤â¤¤¤¤¤À¤í¤¦¡£
(¥µ¥Ö¥ë¡¼¥Á¥ó¤Î¾Ï¤ò»²¾È¡£See section ¥µ¥Ö¥ë¡¼¥Á¥ó.)
`do EXPR' ¤È¤Îº®Íð¤òËɤ°¤¿¤á¡¢³ç¸Ì¤ÏɬÍפǤ¢¤ë¡£
SUBROUTINE ¤Ï°ì¥¹¥«¥é¡¼ÊÑ¿ô¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£
¤³¤Î¾ì¹ç¼Â¹Ô¤¹¤Ù¤¥µ¥Ö¥ë¡¼¥Á¥ó¤Î̾Á°¤Ï¤½¤ÎÊÑ¿ô¤«¤é¼è¤ê½Ð¤µ¤ì¤ë¡£
Ê̤νñ¤Êý¤È¤·¤Æ(¤½¤·¤Æ˾¤Þ¤·¤¤½ñ¤Êý¤È¤·¤Æ)¡¢
̾Á°¤ÎÁ°¤Ë &
¤ò¤Ä¤±¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó¤ò¥³¡¼¥ë¤·¤Æ¤âÎɤ¤¡£
Îã: &foo(@args)
°ú¿ô¤òÅϤµ¤Ê¤¤¤Î¤Ç¤¢¤ì¤Ð¡¢³ç¸Ì¤ò»È¤¦É¬ÍפϤʤ¤¡£
³ç¸Ì¤ò¾Êά¤·¤¿¾ì¹ç¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤Ë¤ÏÇÛÎó @_
¤ÏÅϤµ¤ì¤Ê¤¤¡£
&
·Á¼°¤Ï defined
¤ª¤è¤Ó undef
¤Ë
¥µ¥Ö¥ë¡¼¥Á¥ó¤ò»Ø¼¨¤¹¤ë¤Î¤Ë¤â»È¤¨¤ë¡£
if (defined &$var) { &$var($parm); undef &$var; }
do 'stat.pl';¤Ï¡¢
eval `cat stat.pl`;¤ÈÁ´¤¯Æ±¤¸¤Ç¤¢¤ë¡£ (¤è¤ê¸úΨŪ¤Ç¡¢¤è¤ê´Ê·é¤Ç¡¢¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Ç¤Î¥Õ¥¡¥¤¥ë̾¤ÏÀµ¤·¤¯¡¢ ¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤Ê¤±¤ì¤Ð
-I
¤Ç»ØÄꤵ¤ì¤¿¥é¥¤¥Ö¥é¥ê¤ò
Á´¤Æ¸¡º÷¤¹¤ëÅÀ¤¬°Û¤Ê¤ë¡£See section {@tt@INC} : perl ¥¹¥¯¥ê¥×¥È¤òõ¤¹¾ì½ê¤Î¥ê¥¹¥È.)
¤·¤«¤·¡¢¥³¡¼¥ë¤¹¤ëËè¤Ë parse ¤·Ä¾¤¹¤Î¤ÏƱ¤¸¤Ê¤Î¤Ç¡¢
¥ë¡¼¥×¤ÎÃæ¤Ç»ÈÍѤ¹¤ëºÝ¤Ë¤Ï -P
¥ª¥×¥·¥ç¥ó
¤ª¤è¤Ó #include
¤ò»È¤Ã¤¿Êý¤¬¤è¤¤(¼ã´³Î©¤Á¾å¤²»þ´Ö¤¬Áý¤¨¤ë¤¬)¡£
#include
¤ÎÌäÂêÅÀ¤Ï¡¢cpp ¤Ï #
¤¬¥³¥á¥ó¥È¤Ç¤¢¤ë¤³¤È¤ò
¤ï¤«¤Ã¤Æ¤¯¤ì¤Ê¤¤¤³¤È¤Ç¤¢¤ë -- ¥³¥á¥ó¥È¤À¤±¤«¤é¤Ê¤ë¹Ô¤Ë¤Ï `;#' ¤ò
»È¤¦¤³¤È¤Ë¤Ê¤ë¡£
Ãí°Õ:do $foo; # ¥Õ¥¡¥¤¥ë¤òɾ²Á¤¹¤ë do $foo(); # ¥µ¥Ö¥ë¡¼¥Á¥ó¤ò¸Æ¤Ö¥é¥¤¥Ö¥é¥ê¥ë¡¼¥Á¥ó¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Ë¤Ï
require
¥ª¥Ú¥ì¡¼¥¿¤¬¤è¤¤¡£
See section require.do {}
¹½Â¤¤ÎÃæ¤ò½ü¤¯
¥×¥í¥°¥é¥à¤ÎËÜÂÎÆâ¤Î¥é¥Ù¥ë¤Ë¤·¤« goto
¤Ç¤¤Ê¤¤¡£
goto
¤Ï¤¢¤Þ¤ê¸úΨŪ¤Ë¤Ï¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤Æ¤ª¤é¤º¡¢
sed-to-perl ÊÑ´¹¤òÍưפˤ·¤Æ¤¤¤ë¤À¤±¤Ç¤¢¤ë¡£»ä¤¬¤¤¤Ä¡¢
sed ¥¹¥¯¥ê¥×¥È¤Î¥µ¥Ý¡¼¥È¤Ï»Ä¤·¤¿¤Þ¤Þ¤³¤Î¥»¥Þ¥ó¥Æ¥£¥¯¥¹¤òÊѹ¹¤¹¤ë¤«¤ï¤«¤é¤Ê¤¤¡£
»È¤¤¤¿¤±¤ì¤Ð¼«¤é¤ÎÀÕǤ¤Ç»È¤¦¤³¤È¡£Á´¤¯»È¤ï¤Ê¤¤¤Î¤¬°ìÈÖÎɤ¤¡£last
¥³¥Þ¥ó¥É¤Ï C ¤Ç¤Î break(¥ë¡¼¥×Ãæ¤Ç»ÈÍѤµ¤ì¤ë)
¤È»÷¤Æ¤¤¤ë¡£¸½ºß¼Â¹ÔÃæ¤Î¥ë¡¼¥×¤«¤éľ¤Á¤ËÈ´¤±½Ð¤¹¡£
LABEL ¤ò¾Êά¤¹¤ë¤È¡¢ºÇ¤â±ü¤Î¥ë¡¼¥×¤ò¹½À®¤¹¤ë°Ï¤ß¤ÎºÇ¸å¤Ë¤È¤Ö¡£
continue
¤¬¤â¤·¤¢¤Ã¤Æ¤â¡¢¼Â¹Ô¤µ¤ì¤Ê¤¤¡£
line: while (<STDIN>) { last line if /^$/; # ¥Ø¥Ã¥À¡¼¤¬½ª¤ï¤Ã¤¿¤éÈ´¤±¤ë ... }
next
¥³¥Þ¥ó¥É¤Ï C ¤Ë¤ª¤±¤ë continue ¤Ë»÷¤Æ¤¤¤Æ¡¢
¥ë¡¼¥×¤Î¼¡¤Î·«¤êÊÖ¤·¤ò¹Ô¤¦¡£
line: while (<STDIN>) { next line if /^#/; # ¥³¥á¥ó¥È¤Ï¼Î¤Æ¤ë ... }Ãí°Õ:
continue
¥Ö¥í¥Ã¥¯¤¬¾åÎã¤Ë¤¢¤ì¤Ð¡¢
̵»ë¤µ¤ì¤ë¹Ô¤Ç¤¢¤Ã¤Æ¤â¼Â¹Ô¤µ¤ì¤ë¡£LABEL ¤ò¾Êά¤·¤¿¾ì¹ç¡¢
next
¤Ï³ç¸Ì¤Ç°Ï¤Þ¤ì¤¿¥ë¡¼¥×¤ÎºÇ¸å¤Ë¤È¤Ö¡£redo
¥³¥Þ¥ó¥É¤Ï¾ò·ï¤òɾ²Á¤¹¤ë¤³¤È¤Ê¤¯¥ë¡¼¥×¥Ö¥í¥Ã¥¯¤òºÆ¤Ó¼Â¹Ô¤¹¤ë¡£
continue
¥Ö¥í¥Ã¥¯¤¬¤â¤·¤¢¤Ã¤Æ¤â¡¢¼Â¹Ô¤µ¤ì¤Ê¤¤¡£
LABEL ¤ò¾Êά¤¹¤ë¤È¡¢ºÇ¤âÆ⦤ÎÊĤ¸¤¿¥ë¡¼¥×¤òÍѤ¤¤ë¡£
¤³¤Î¥³¥Þ¥ó¥É¤ÏÄ̾
ÆþÎϤµ¤ì¤¿ÆâÍƤˤĤ¤¤Æ¼«Ê¬¼«¿È¤Ë±³¤ò¤Ä¤¯¤è¤¦¤Ê¥×¥í¥°¥é¥à¤ÇÍѤ¤¤ë¡£
# ñ½ã¤Ê Pascal ¥³¥á¥ó¥È½üµî¥×¥í¥°¥é¥à # (Ãí°Õ: ʸ»úÎóÃæ¤Ë {} ¤¬¤Ê¤¤¤È²¾Äꤷ¤Æ¤¤¤ë) line: while (<STDIN>) { while (s|({.*}.*){.*}|$1 |) {} s|{.*}| |; if (s|{.*| |) { $front = $_; while (<STDIN>) { if (/}/) { # ¥³¥á¥ó¥È¤Î½ª¤ï¤ê? s|^|$front{|; redo line; } } } print; }
return
¤òÌÀ¼¨¤¹¤ë¤È¡¢¼ã´³ÃÙ¤¯¤Ê¤ë¡£$_
¤ò»È¤¦¡£
$_
¤Î¥µ¥¤¥ó¤òÊÖ¤¹¡£$_
) ¤òÊÖ¤¹¡£$_
¤Î¥ë¡¼¥È¤òÊÖ¤¹¡£$_
¤ò»ÈÍѤ¹¤ë¡£$_
¤Î log ¤òÊÖ¤¹¡£srand()
¤â»²¾È¡£rand
±é»»»Ò¤ÇÍѤ¤¤ëÍð¿ô¤Î seed ¤ò¥»¥Ã¥È¤¹¤ë¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢srand(time)
¤ò¼Â¹Ô¤¹¤ë¡£gmtime()
¤ä localtime()
¤Ë»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
gmtime
¤ª¤è¤Ó localtime
¤Ë¤Ä¤¤¤Æ¤Ï
See section ÊÑ´¹´Ø¿ô.time
´Ø¿ô¤¬ÊÖ¤¹»þ´Ö¤ò Greenwich timezone ¤È¤·¤Æ
Í×ÁÇ¿ô 9 ¤ÎÇÛÎó¤ËÊÑ´¹¤¹¤ë¡£Åµ·¿Åª¤Ë°Ê²¼¤Î¤è¤¦¤Ë»ÈÍѤµ¤ì¤ë¡£
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);ÇÛÎó¤ÎÁ´Í×ÁǤϿôÃͤǤ¢¤ê¡¢ struct tm ¤«¤éľÀÜÆÀ¤é¤ì¤¿¤â¤Î¤Ç¤¢¤ë¡£ ¤³¤Î¤¿¤á¡¢
$mon
¤Ï 0 ¤«¤é 11 ¤Þ¤Ç¡¢
$wday
¤Ï 0 ¤«¤é 6 ¤Þ¤Ç¤ÎÃͤò¼è¤ë¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢gmtime(time)
¤ò¼Â¹Ô¤¹¤ë¡£time
´Ø¿ô¤¬ÊÖ¤¹·Á¼°¤Î»þ´Ö¤ò local timezone ¤È¤·¤Æ
Í×ÁÇ¿ô 9 ¤ÎÇÛÎó¤ËÊÑ´¹¤¹¤ë¡£Åµ·¿Åª¤Ë°Ê²¼¤Î¤è¤¦¤ËÍѤ¤¤ë¡£
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);ÇÛÎó¤ÎÍ×ÁǤϤ¹¤Ù¤Æ¿ôÃͤǡ¢struct tm ¤«¤éľÀÜÆÀ¤é¤ì¤ë¤â¤Î¤Ç¤¢¤ë¡£ ¤³¤Î¤¿¤á¡¢
$mon
¤Ï 0 ¤«¤é 11¡¢$wday
¤Ï 0 ¤«¤é 6 ¤ÎÃͤò¼è¤ë¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢localtime(time)
¤ò¼Â¹Ô¤¹¤ë¡£
time
¤Ë¤Ä¤¤¤Æ¤Ï See section ¿ô³Ø´Ø¿ô.0
¤Þ¤¿¤Ï 0x
¤Ç»Ï¤Þ¤ëʸ»úÎó¤ÎÊÑ´¹¤Ë¤Ä¤¤¤Æ¤Ï oct()
¤ò»²¾È¡£)¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢$_
¤ò»ÈÍѤ¹¤ë¡£0x
¤Ç»Ï¤Þ¤ë¾ì¹ç¤ÏÂå¤ï¤ê¤Ë 16 ¿Êʸ»úÎó¤Ç¤¢¤ë¤È²ò¼á¤¹¤ë¡£)
¼¡¤ÎÎã¤Ç¤Ï¡¢É¸½àŪ¤Êµ½Ò¤Ë¤è¤ë 10¡¢8¡¢16 ¿Ê¤ò°·¤¦¤³¤È¤¬¤Ç¤¤ë¡£
$val = oct($val) if $val =~ /^0/;EXPR ¤ò¾Êά¤·¤¿¾ì¹ç¡¢
$_
¤ò»ÈÍѤ¹¤ë¡£
$_
¤ò»ÈÍѤ¹¤ë¡£vec()
¤¬ÊÖ¤¹¥Ù¥¯¥È¥ë¤ÏÏÀÍý±é»»»Ò |
¡¢&
¡¢^
¤òÍѤ¤¤Æ
Áàºî¤Ç¤¤ë¡£Î¾¥ª¥Ú¥é¥ó¥É¤¬Ê¸»úÎó¤Î¾ì¹ç¤Ï¥Ó¥Ã¥È¥Ù¥¯¥È¥ë±é»»¤Ç¤¢¤ë¤È²¾Äꤹ¤ë¡£
¤³¤Î²ò¼á¤Ï¥×¥í¥°¥é¥à¤Ë¾¯¤Ê¤¯¤È¤â°ì¤Ä¤Î vec()
¤¬¤Ê¤¤¤È¤Ê¤µ¤ì¤Ê¤¤¡£
(¸Å¤¤¥×¥í¥°¥é¥à¤ò¼é¤ë¤¿¤á)
¥Ó¥Ã¥È¥Ù¥¯¥È¥ë¤òʸ»úÎó¤ä 0 ¤È 1 ¤ÎÇÛÎó¤ËÊÑ´¹¤¹¤ë¤Ë¤Ï¡¢
¼¡¤Î¤è¤¦¤Ë¤¹¤ì¤Ð¤è¤¤¡£
$bits = unpack("b*", $vector); @bits = split(//, unpack("b*", $vector));Àµ³Î¤Ê¥Ó¥Ã¥ÈŤ¬¤ï¤«¤Ã¤Æ¤¤¤ë¤Ê¤é¡¢
*
¤ÎÂå¤ï¤ê¤Ë¤½¤ì¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£pack
¤¹¤ë¡£
¹½Â¤ÂΤò´Þ¤àʸ»úÎó¤òÊÖ¤¹¡£TEMPLATE ¤Ï¤Ò¤È³¤¤Îʸ»úÎó¤Ç¡¢
³Æʸ»ú¤Ï°Ê²¼¤Î¤è¤¦¤ËÃͤΥª¡¼¥À¡¼¤ª¤è¤Ó¥¿¥¤¥×¤òɽ¤¹¡£
A ¥¢¥¹¥¡¼Ê¸»úÎó(¥¹¥Ú¡¼¥¹¤¬ pad ¤µ¤ì¤ë)
a ¥¢¥¹¥¡¼Ê¸»úÎó(¥Ì¥ë¤¬ pad ¤µ¤ì¤ë)
c signed char
C unsigned char
s signed short
S unsigned short
i signed integer
I unsigned integer
l signed long
L unsigned long
n short("network" ¥ª¡¼¥À¡¼)
N long("network" ¥ª¡¼¥À¡¼)
f ñÀºÅÙÉâÆ°¾®¿ôÅÀ(native format)
d ÇÜÀºÅÙÉâÆ°¾®¿ôÅÀ( ¡· )
p string ¤Ø¤Î¥Ý¥¤¥ó¥¿
x ¥Ì¥ë¥Ð¥¤¥È
X 1 ¥Ð¥¤¥È¸åÂह¤ë
@ ÀäÂаÌÃ֤ޤǥ̥ë¤ÇËä¤á¤ë
u uuencode ¤µ¤ì¤¿Ê¸»úÎó
b ¥Ó¥Ã¥Èʸ»úÎó
(vec()
¤Î¤è¤¦¤Ê¡¢¾º½ç¤Î¥Ó¥Ã¥È¥ª¡¼¥À¡¼(ascending bit order))
B ¥Ó¥Ã¥Èʸ»úÎó(¹ß½ç¤Î¥Ó¥Ã¥È¥ª¡¼¥À¡¼(descending bit order))
h 16¿Êʸ»úÎó(Äã nybble ¤¬Àè¤ËÍè¤ë)
H 16¿Êʸ»úÎó(¹â nybble ¤¬Àè¤ËÍè¤ë)
¥ª¥×¥·¥ç¥ó¤È¤·¤Æ¿ô»ú¤ò³Æʸ»ú¤Î¸å¤Ë¤Ä¤±¤Æ¡¢·«¤êÊÖ¤·¿ô¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
`a'¡¢`A'¡¢`b'¡¢`B'¡¢`h'¡¢`H' °Ê³°¤Î¥¿¥¤¥×¤Ç¤Ï¡¢
»ØÄꤵ¤ì¤¿¿ô¤ÎÃͤò LIST ¤«¤é¼è¤ë¡£
¥ê¥Ô¡¼¥ÈÃͤȤ·¤Æ *
¤ò»È¤¦¤È»Ä¤êÁ´Éô¤ò¼¨¤¹¡£
`a' ¤È `A' ¤Ç¤Ï¡¢Ãͤϰì¤Ä¤Ç¡¢»ØÄꤵ¤ì¤¿Ä¹¤µ¤Î°ì¤Ä¤Îʸ»úÎó¤È¤·¤Æ¡¢
ɬÍפʤé¥Ì¥ë¤ä¥¹¥Ú¡¼¥¹¤ò pad ¤¹¤ë¡£
(unpack
¤ÎºÝ¤Ë¤Ï¡¢
`A' ¤Ï¸å¤Ë³¤¯¥¹¥Ú¡¼¥¹¤ä¥Ì¥ë¤ò¼è¤ê½ü¤¯¤¬¡¢
`a' ¤Î¾ì¹ç¤Ï¤½¤¦¤Ç¤Ï¤Ê¤¤¡£)
ƱÍͤˡ¢`b' ¤È `B' ¤Ï»ØÄꤷ¤¿¥Ó¥Ã¥È¿ôʬ¤Îʸ»úÎó¤ò pack ¤¹¤ë¡£
`h' ¤È `H' ¤Ï»ØÄꤷ¤¿¿ô¤Î nybbles ¤ò pack ¤¹¤ë¡£
¼Â¿ô(ñÀºÅÙ¡¢ÇÜÀºÅÙ)¤Ï native machine format ¤Î¤ß¤Ç¤¢¤ë¡£
ÉâÆ°¾®¿ôÅÀ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤Ï¤¤¤í¤¤¤í¤¢¤ê¡¢
ɸ½à¤Î network ɽ¸½¤¬¤Ê¤¤¤Î¤Ç¡¢¸ò´¹¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
¤³¤Î¤¿¤á¡¢¤¢¤ë¥Þ¥·¥ó¤Ç pack
¤µ¤ì¤¿ÉâÆ°¾®¿ôÅÀ¥Ç¡¼¥¿¤Ï
¾¤Î¥Þ¥·¥ó¤Ç¤ÏÆɤळ¤È¤¬¤Ç¤¤Ê¤¤ ---
¤¿¤È¤¨Î¾Êý¶¦ IEEE ¤Î floating point arithmetic ¤ò»È¤Ã¤Æ¤¤¤¿¤È¤·¤Æ¤â
(¥á¥â¥êɽ¸½¤Î endian-ness ¤Ï IEEE ¤Î¥¹¥Ú¥Ã¥¯¤Ë¤Ï¤Ê¤¤¤«¤é)¡£
perl ¤ÏÆâÉô¤ÎÁ´¿ôÃÍ·×»»¤ËÇÜÀºÅÙ¤òÍѤ¤¤Æ¤¤¤ë¤Î¤Ç¡¢
double -> float -> double ¤È¤¤¤¦ÊÑ´¹¤ò¤¹¤ë¤ÈÀºÅÙ¤¬°¤¯¤Ê¤ë
(¤¹¤Ê¤ï¤Á¡¢unpack("f", pack("f", $foo))
¤Ï
ÉáÄÌ $foo
¤È°ìÃפ·¤Ê¤¤)¤³¤È¤ËÃí°Õ¡£
$foo = pack("cccc",65,66,67,68); # foo ¤Ï "ABCD" ¤È¤Ê¤ë $foo = pack("c4",65,66,67,68); # Ʊ¤¸¤³¤È $foo = pack("ccxxcc",65,66,67,68); # foo ¤Ï "AB\0\0CD" ¤È¤Ê¤ë $foo = pack("s2",1,2); # ¥ê¥È¥ë¡¦¥¨¥ó¥Ç¥£¥¢¥ó¤Ç¤Î "\1\0\2\0" # ¥Ó¥Ã¥°¡¦¥¨¥ó¥Ç¥£¥¢¥ó¤Ç¤Î "\0\1\0\2" $foo = pack("a4","abcd","x","y","z"); # "abcd" $foo = pack("aaaa","abcd","x","y","z"); # "axyz" $foo = pack("a14","abcdefg"); # "abcdefg\0\0\0\0\0\0\0" $foo = pack("i9pl", gmtime); # ¼ÂºÝ¤Î¹½Â¤ÂÎ tm (»ä¤Î¥·¥¹¥Æ¥à¤Ç¤Ï) sub bintodec { unpack("N", pack("B32", substr("0" x 32 . shift, -32))); }
unpack
´Ø¿ô¤Ç¤â¡¢Æ±¤¸¥Æ¥ó¥×¥ì¡¼¥È¤òÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¡£
unpack
¤Ï pack
¤ÎµÕ¤ò¹Ô¤¦:pack
´Ø¿ô ¤ÈƱ¤¸¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤¢¤ë¡£
°Ê²¼¤Ï substring
¤ò¹Ô¤¦¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÎã¤Ç¤¢¤ë¡£
sub substr { local($what,$where,$howmuch) = @_; unpack("x$where a$howmuch", $what); }¤½¤·¤Æ¡¢
sub ord { unpack("c",$_[0]); }¤µ¤é¤Ë¡¢¥Õ¥£¡¼¥ë¥É¤Ë
%<¿ô»ú>
¤È¤¤¤¦Åº¤¨»ú¤ò¤Ä¤±¤ë¤È¡¢
¥¢¥¤¥Æ¥à¤½¤Î¤â¤Î¤ÎÂå¤ï¤ê¤Ë¡¢¥¢¥¤¥Æ¥à¤Î<¿ô»ú>¥Ó¥Ã¥È¤Î¥Á¥§¥Ã¥¯¥µ¥à¤¬ÆÀ¤é¤ì¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Ï 16 ¥Ó¥Ã¥È¥Á¥§¥Ã¥¯¥µ¥à¤Ç¤¢¤ë¡£
Î㤨¤Ð¡¢¼¡¤ÎÎã¤Ç¤Ï System V ¤Î sum ¥×¥í¥°¥é¥à¤ÈƱ¤¸Ãͤ¬ÆÀ¤é¤ì¤ë¡£
while(<>) { $checksum += unpack("%16C*", $_); } $checksum %= 65536;See section pack.
s/\n//
¤è¤ê¤â¸úΨ¤¬¤è¤¤¡£
ÊÑ¿ô¤ò¾Êά¤·¤¿¾ì¹ç¡¢$_
¤ò»È¤¦¡£
while (<>) { chop; # ºÇ¸å¤Î \n ¤ò¼è¤ë @array = split(/:/); ...º¸ÊÕÃͤǤ¢¤ì¤Ð°ú¿ô¤Ï²¿¤Ç¤â¤¤¤¤¡£
chop($cwd = `pwd`); chop($answer = <STDIN>);¥ê¥¹¥È¤ò
chop
¤·¤¿¾ì¹ç¤Ï¡¢Á´Í×ÁǤò chop
¤·¡¢
ºÇ¸å¤Ë chop
¤·¤¿Ê¸»ú¤òÊÖ¤¹¡£
die
ʸ¤¬¼Â¹Ô¤µ¤ì¤¿¾ì¹ç¡¢
eval
¤Ï undefined value ¤òÊÖ¤·¡¢
$@
¤Ë¤Ï¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£
¥¨¥é¡¼¤¬¤Ê¤±¤ì¤Ð $@
¤Ï¥Ì¥ë¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤ë¡£
EXPR ¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Ï¡¢$_
¤òɾ²Á¤¹¤ë¡£
expression ¤ÎºÇ¸å¤Ë¥»¥ß¥³¥í¥ó¤¬¤â¤·¤¢¤ì¤Ð¡¢expression ¤«¤é½ü¤«¤ì¤ë¡£
$@
¤Ë¤Ä¤¤¤Æ¤Ï See section @hbox{@hbox to 1.6em{@tt@$@@hfil} : ºÇ¸å¤Ë¹Ô¤Ã¤¿ eval ¤Î¥·¥ó¥¿¥Ã¥¯¥¹¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸}.
eval
¤ÏÃ×̿Ū¥¨¥é¡¼¤ò¥È¥é¥Ã¥×¤¹¤ë¤Î¤Ç¡¢
¤¢¤ëµ¡Ç½(Î㤨¤Ð dbmopen
¤ä symlink
)¤¬
¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò·èÄꤹ¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
¤Þ¤¿¡¢eval
¤Ï¡¢perl ¤ÎÎã³°¥È¥é¥Ã¥×µ¡¹½(exception trapping mechanism)
¤Ç¤â¤¢¤ë¡£¤³¤ÎÎã³°¤òµ¯¤³¤¹¤¿¤á¤Ë¤Ï die
±é»»»Ò¤òÍѤ¤¤ë¡£
¼Â¹Ô¤¹¤ë¥³¡¼¥É¤¬ÊѲ½¤·¤Ê¤¤¤Î¤Ç¤¢¤ì¤Ð¡¢
eval-BLOCK
·Á¼°¤ò»È¤¦¤³¤È¤Ë¤è¤ê¡¢
Ëè²ó¥³¥ó¥Ñ¥¤¥ë¤·Ä¾¤¹ÉÔÍø±×¤òÈï¤ë¤³¤È¤Ê¤¯
¼Â¹Ô»þ¤Î¥¨¥é¡¼¤ò¥È¥é¥Ã¥×¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¥¨¥é¡¼¤Ï¡¢¤â¤·¤¢¤ì¤Ð¡¢Æ±ÍÍ¤Ë $@
¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£
¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤µ¤ì¤¿Ê¸»úÎó(EXPR)¤ò eval
¤¹¤ë¤Î¤âƱÍͤθú²Ì¤¬¤¢¤ë¤¬¡¢
eval-EXPR
¤Ï¥·¥ó¥¿¥Ã¥¯¥¹¥¨¥é¡¼¤ò¼Â¹Ô»þ¤Ë $@
¤ËÊÖ¤¹¤Î¤ËÂФ·¡¢
eval-BLOCK
¤Ï¥·¥ó¥¿¥Ã¥¯¥¹¥¨¥é¡¼¤ò¥³¥ó¥Ñ¥¤¥ë»þ¤ËÊÖ¤¹ÅÀ¤¬°Û¤Ê¤ë¡£
eval-EXPR
·Á¼°¤Ï¡¢
¤½¤Î¼Â¹Ô¤¬ºÇ½é¤ËÀ®¸ù¤·¤¿»þÅÀ¤Ç eval-BLOCK
·Á¼°¤ËºÇŬ²½¤µ¤ì¤ë¡£
(ʸ»úÎóÃÖ´¹¤Ë¤ª¤¤¤Æ e
½¤¾þ»Ò¤òÍѤ¤¤¿¾ì¹ç¡¢
ÃÖ´¹Â¦¤Ï¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤µ¤ì¤¿Ê¸»úÎó¤Ç¤¢¤ë¤È¸«¤Ê¤µ¤ì¤ë¤Î¤Ç¡¢
ƱÍͤκÇŬ²½¤¬¤³¤Î¾ì¹ç¤Ë¤â¤Ê¤µ¤ì¤ë¡£)
Îã:
# 0 ½ü»»¤òÃ×̿Ū¥¨¥é¡¼¤Ë¤·¤Ê¤¤ eval { $answer = $a / $b; }; warn $@ if $@; # ºÇ½é¤Ë»È¤Ã¤¿¸å¡¢Æ±¤¸¤â¤Î¤ËºÇŬ²½¤µ¤ì¤ë eval '$answer = $a / $b'; warn $@ if $@; # ¥³¥ó¥Ñ¥¤¥ë»þ¥¨¥é¡¼ eval { $answer = }; # ¼Â¹Ô»þ¥¨¥é¡¼ eval '$answer ='; # $@ ¤ò¥»¥Ã¥È¤¹¤ë
$[
¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ì¤Ð¤½¤ÎÃͤǤ¢¤ë¡£
SUBSTR ¤¬¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¥Ù¡¼¥¹¤«¤é 1 ¤ò°ú¤¤¤¿ÃͤòÊÖ¤¹¡£
Ä̾ï -1 ¤Ç¤¢¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$[@hfil} : ÇÛÎó¤ÎºÇ½é¤ÎÍ×ÁǤ䡢¥µ¥Ö¥¹¥È¥ê¥ó¥°¤ÎºÇ½é¤Îʸ»ú¤Îź¤¨»ú}.
$_
¤ÎŤµ¤òÊÖ¤¹¡£index
¤ÈƱ¤¸¤è¤¦¤ÊÆ°ºî¤ò¤¹¤ë¤¬¡¢
°ã¤¤¤Ï STR Æâ¤ËºÇ¸å¤Ë¸½¤ì¤ë SUBSTR ¤Î°ÌÃÖ¤òÊÖ¤¹¤³¤È¤Ç¤¢¤ë¡£
POSITION ¤ò»ØÄꤹ¤ë¤È¡¢
¤½¤Î°ÌÃÖ¤Þ¤¿¤Ï¤½¤ì¤è¤êÁ°¤ÇºÇ¸å¤Ë¸½¤ì¤ë°ÌÃÖ¤òÊÖ¤¹¡£
See section index.$[
¤Ë¥»¥Ã¥È¤¹¤ë¤³¤È¤ÇÊѤ¨¤ë¤³¤È¤¬¤Ç¤¤ë¡£OFFSET ¤¬Éé¤Î¾ì¹ç¤Ï¡¢
ʸ»úÎó¤Î½ª¤ï¤ê¤«¤é¤½¤Î¿ôʬÌá¤Ã¤¿½ê¤«¤é»Ï¤á¤ë¡£
LEN ¤ò¾Êά¤¹¤ë¤È¡¢Ê¸»úÎó¤Î»Ä¤êÁ´Éô¤òÊÖ¤¹¡£
substr()
´Ø¿ô¤Ïº¸ÊÕÃͤȤ·¤Æ»È¤¦¤³¤È¤â¤Ç¤¤ë¤¬¡¢
¤³¤Î¾ì¹ç EXPR ¤¬ º¸ÊÕÃͤǤʤ¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
LEN ¤è¤ê¤âû¤¤¤â¤Î¤òÂåÆþ¤¹¤ë¤È¡¢¤½¤Îʸ»úÎó¤Ïû¤¯¤Ê¤ê¡¢
LEN ¤è¤ê¤âŤ¤¤â¤Î¤òÂåÆþ¤¹¤ë¤È¤½¤ì¤Ë¹ç¤ï¤»¤ÆŤ¯¤Ê¤ë¡£
ʸ»úÎó¤ÎŤµ¤òÊѤ¨¤Ê¤¤¾ì¹ç¤Ï sprintf
¤òÍѤ¤¤Æ
¥Ñ¥Ç¥£¥ó¥°¤Þ¤¿¤ÏÀڼΤƤò¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
See section @hbox{@hbox to 1.6em{@tt@$[@hfil} : ÇÛÎó¤ÎºÇ½é¤ÎÍ×ÁǤ䡢¥µ¥Ö¥¹¥È¥ê¥ó¥°¤ÎºÇ½é¤Îʸ»ú¤Îź¤¨»ú}.
foreach $key (keys %ARRAY) { delete $ARRAY{$key}; }(¤¬¡¢
reset
¥³¥Þ¥ó¥É¤ò»È¤Ã¤¿Êý¤¬Â®¤¤¤À¤í¤¦¡£
undef %ARRAY
¤Ï¤â¤Ã¤È®¤¤¤À¤í¤¦¡£)each()
, key()
, values()
´Ø¿ô¥³¡¼¥ë¤Ç¶¦Í¤µ¤ì¤ë¡£
¼¡¤ÎÎã¤Ç¤Ï printenv ¤Î¤è¤¦¤Ë´Ä¶¤ò¥×¥ê¥ó¥È¥¢¥¦¥È¤¹¤ë¤¬¡¢½çÈÖ¤¬°Û¤Ê¤ë¡£
while (($key,$value) = each %ENV) { print "$key=$value\n"; }See section keys, ¤ª¤è¤Ó See section values.
$_
¤Ë¥»¥Ã¥È¤·¤Ê¤¬¤é)¡¢
expression ¤¬ true ¤Ç¤¢¤ë¤Èɾ²Á¤µ¤ì¤¿Í×ÁǤ«¤é¤Ê¤ëÇÛÎó¤òÊÖ¤¹¡£
¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢expression ¤¬ true ¤È¤Ê¤Ã¤¿²ó¿ô¤òÊÖ¤¹¡£
@foo = grep(!/^#/, @bar); # ¥³¥á¥ó¥È¤ò̵»ë¤¹¤ëÃí°Õ:
$_
¤ÏÇÛÎóÃͤؤλ²¾È¤È¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç¡¢
ÇÛÎóÍ×ÁǤòÊѹ¹¤¹¤ë¤Î¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¡£¤³¤ì¤ÏÊØÍø¤Ç¤¢¤ë°ìÊý¡¢
LIST ¤¬Ì¾Á°¤Î¤Ä¤¤¤¿ÇÛÎó¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
¤Á¤ç¤Ã¤ÈÊѤʷë²Ì¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë¡£
$_ = join(':',$login,$passwd,$uid,$gid,$gcos,$home,$shell);See section split.
values()
¤ä each()
´Ø¿ô¤Î½ÐÎϤÈƱ¤¸¤Ç¤¢¤ë
(Ï¢ÁÛÇÛÎó¤¬Êѹ¹¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð)¡£
°Ê²¼¤Ï´Ä¶¤ò½ÐÎϤ¹¤ë¤Þ¤¿Ê̤ÎÊýË¡¤Ç¤¢¤ë¡£
@keys = keys %ENV; @values = values %ENV; while ($#keys >= 0) { print pop(@keys), '=', pop(@values), "\n"; }¤Þ¤¿¤Ï¡¢¥¡¼¤Ç¥½¡¼¥È¤·¤Æ¤ß¤ë¤È¡¢
foreach $key (sort(keys %ENV)) { print $key, '=', $ENV{$key}, "\n"; }See section each, ¤ª¤è¤Ó See section values.
$tmp = $ARRAY[$#ARRAY--];¤ÈƱ¤¸¸ú²Ì¤¬¤¢¤ë¡£ÇÛÎó¤ËÍ×ÁǤ¬°ì¤Ä¤â¤Ê¤¤¾ì¹ç¤Ï undefined value ¤òÊÖ¤¹¡£ See section push.
for $value (LIST) { $ARRAY[++$#ARRAY] = $value; }¤ÈƱ¤¸¸ú²Ì¤ò»ý¤Ä¤¬¡¢¤è¤ê¸úΨ¤¬¤è¤¤¡£ See section pop.
@ARGV
¤ò shift
¤·¡¢
¥µ¥Ö¥ë¡¼¥Á¥ó¤Ç¤Ï @_
¤ò shift
¤¹¤ë¡£
(¤³¤ì¤Ï lexically(?) ¤Ë·èÄꤵ¤ì¤ë¡£)
unshift()
¡¢push()
¡¢pop()
¤â»²¾È¤Î¤³¤È¡£
shift()
¤È unshift()
¤Ï¡¢
push()
¤È pop()
¤¬ÇÛÎó¤Î±¦¤Ë¤Ä¤¤¤Æ¹Ô¤¦¤Î¤ÈƱ¤¸¤³¤È¤ò
ÇÛÎó¤Îº¸¤Ë¤Ä¤¤¤Æ¹Ô¤¦¡£
See section unshift, See section push, ¤ª¤è¤Ó See section pop.<=>
¤ä cmp
¤È¤¤¤Ã¤¿±é»»»Ò¤¬ÂçÊÑÊØÍø¤Ç¤¢¤ë¡£)
SUBROUTINE ¤Ï¥¹¥«¥é¡¼ÊÑ¿ô¤Î̾Á°¤Ç¤â¤è¤¤¡£
¤³¤Î¾ì¹ç¤½¤ÎÊÑ¿ô¤ÎÃͤ¬»ÈÍѤ¹¤ë¥µ¥Ö¥ë¡¼¥Á¥ó¤Î̾Á°¤òɽ¤¹¡£
¥µ¥Ö¥ë¡¼¥Á¥ó̾¤ÎÂå¤ï¤ê¤ËǤ°Õ¤Î BLOCK ¤ò»ØÄꤷ¤Æ¡¢
¥¤¥ó¥é¥¤¥ó¤Î¥½¡¼¥È¥µ¥Ö¥ë¡¼¥Á¥ó¤È¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¸úΨ¤òÎɤ¯¤¹¤ë¤¿¤á¡¢Ä̾ï¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¥³¡¼¥ë¤ò¤È¤Ð¤·¤Æ¤¤¤ë¡£
¤³¤Î¤¿¤á¡¢¼¡¤Î±Æ¶Á¤¬¤¢¤ë¡£
¥µ¥Ö¥ë¡¼¥Á¥ó¤ÏºÆµ¢Åª¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
¤Þ¤¿¡¢Èæ³Ó¤µ¤ì¤ë 2 Í×ÁÇ¤Ï @_
¤òÄ̤¸¤Æ¤Ç¤Ï¤Ê¤¯¡¢
$a
¤È $b
¤òÄ̤¸¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó¤ËÅϤµ¤ì¤ë¡£(°Ê²¼¤ÎÎã¤ò»²¾È¡£)
¤³¤ì¤é¤Ï»²¾ÈÅϤ·¤Ç¤¢¤ë¤Î¤Ç¡¢$a
¤È $b
¤òÊѹ¹¤·¤Æ¤Ï¤¤¤±¤Ê¤¤¡£
Îã:
# ¼½ñ½ç¤Ç¥½¡¼¥È @articles = sort @files; # ƱÍͤΤâ¤Î¤Ç¥½¡¼¥È¥ë¡¼¥Á¥ó¤òÌÀ¼¨¤·¤¿¤â¤Î @articles = sort {$a cmp $b} @files; # ƱÍͤΤâ¤Î¤ÇµÕ½ç @articles = sort {$b cmp $a} @files; # ¿ôÃÍŪ¤Ë¾º½ç¤Ë¥½¡¼¥È @articles = sort {$a <=> $b} @files; # ¿ôÃÍŪ¤Ë¹ß½ç¤Ë¥½¡¼¥È @articles = sort {$b <=> $a} @files; # ÌÀ¼¨Åª¤Ê¥µ¥Ö¥ë¡¼¥Á¥ó̾¤Ç¥½¡¼¥È sub byage { $age{$a} <=> $age{$b}; # À°¿ô¤Ç¤¢¤ë¤È²¾Äꤷ¤Æ¤¤¤ë } @sortedclass = sort byage @class; sub reverse { $b cmp $a; } @harry = ('dog','cat','x','Cain','Abel'); @george = ('gone','chased','yz','Punished','Axed'); print sort @harry; # ½ÐÎÏ¤Ï AbelCaincatdogx print sort reverse @harry; # ½ÐÎÏ¤Ï xdogcatCainAbel print sort @george, 'to', @harry; # ½ÐÎÏ¤Ï AbelAxedCainPunishedcatchaseddoggonetoxyz
$[ == 0
¤Ç¤¢¤ë¤È²¾Äꤷ¤Æ¤¤¤ë¡£)
push(@a,$x,$y) splice(@a,$#a+1,0,$x,$y) pop(@a) splice(@a,-1) shift(@a) splice(@a,0,1) unshift(@a,$x,$y) splice(@a,0,0,$x,$y) $a[$x] = $y splice(@a,$x,1,$y);¼¡¤ÎÎã¤Ï¡¢ÇÛÎó¤ÎŤµ¤¬ÇÛÎó¤ÎÁ°¤ËÅϤµ¤ì¤ë¤È²¾Äꤷ¤Æ¤¤¤ë¡£
sub aeq { # 2 ¤Ä¤ÎÇÛÎóÃͤòÈæ³Ó¤¹¤ë local(@a) = splice(@_,0,shift); local(@b) = splice(@_,0,shift); return 0 unless @a == @b; # Ʊ¤¸Ä¹¤µ? while (@a) { return 0 if pop(@a) ne pop(@b); } return 1; } if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
@_
¤Ë³ÊǼ¤¹¤ë¡£
(ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤â¡¢¥Ñ¥¿¡¼¥ó delimiter ¤Ë ??
¤ò»ØÄꤹ¤ë¤³¤È¤Ç
@_
¤Ø¤ÎÂåÆþ¤ò¶¯À©¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤¬¡¢
ÊÖ¤êÃͤÏÇÛÎóÃͤΤޤޤǤ¢¤ë¡£))
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢Ê¸»úÎó $_
¤òʬ³ä¤¹¤ë¡£
PATTERN ¤â¾Êά¤¹¤ë¤È¡¢
whitespace (/[ \t\n]+/)
¤Çʬ³ä¤¹¤ë¡£
PATTERN ¤Ë¥Þ¥Ã¥Á¤¹¤ëʸ»ú¤Ï¡¢
Á´¤Æ¥Õ¥£¡¼¥ë¥É¤òʬ¤±¤ë delimiter ¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¤ë
(Ãí°Õ: delimiter ¤Ï 1 »ú¤òĶ¤¨¤Æ¤â¤è¤¤)¡£
LIMIT ¤ò»ØÄꤹ¤ë¤È¡¢¤½¤ì¤òĶ¤¨¤Ê¤¤¿ô¤Ëʬ³ä¤¹¤ë(¾¯¤Ê¤¤¾ì¹ç¤â¤¢¤ë)¡£
LIMIT ¤ò»ØÄꤷ¤Ê¤¤¾ì¹ç¤Ï¡¢Í¾Ê¬¤Ê¥Ì¥ë¥Õ¥£¡¼¥ë¥É¤¬½ü¤«¤ì¤ë
(pop()
¤ò»È¤ª¤¦¤È¤¤¤¦¥æ¡¼¥¶¤Ï¤³¤Î¤³¤È¤ò³Ð¤¨¤Æ¤ª¤¤¤¿Êý¤¬Îɤ¤¤Î¤Ç¤Ï?)¡£
¥Ì¥ëʸ»úÎó¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¿¡¼¥ó(¥Ì¥ë¥Ñ¥¿¡¼¥ó //
¤Èº®Æ±¤·¤Ê¤¤¤è¤¦¤Ë¡£
//
¤Ï¥Ì¥ëʸ»úÎó¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¿¡¼¥ó·²¤Î°ì¤Ä¤Ë¤¹¤®¤Ê¤¤)¤Ï
¤½¤Î¥Ñ¥¿¡¼¥ó¤¬¥Þ¥Ã¥Á¤¹¤ëÁ´¤Æ¤ÎÅÀ¤Ç EXPR ¤ÎÃͤòʸ»ú¤Ëʬ³ä¤¹¤ë¡£
print join(':', split(/ */, 'hi there'));¤Ï `h:i:t:h:e:r:e' ¤ò½ÐÎϤ¹¤ë¡£ LIMIT ¥Ñ¥é¥á¡¼¥¿¤Ï¹Ô¤Î°ìÉô¤òʬ³ä¤¹¤ë¤Î¤Ë»ÈÍѤǤ¤ë¡£
($login, $passwd, $remainder) = split(/:/, $_, 3);(¥ê¥¹¥È¤ËÂåÆþ¤¹¤ë»þ¤Ë LIMIT ¤¬¾Êά¤µ¤ì¤Æ¤¤¤ë¤È¡¢ perl ¤Ï¥ê¥¹¥ÈÃæ¤ÎÊÑ¿ô¤Î¿ô¤è¤ê 1 ¿¤¤¿ô¤ò LIMIT ¤È¤¹¤ë¡£ ¤³¤ì¤ÏÉÔɬÍפʺî¶È¤ò̵¤¯¤¹¤¿¤á¤Ç¤¢¤ë¡£ ¾å¤Î¥ê¥¹¥È¤Ç¤Ï¡¢LIMIT ¤Ï¥Ç¥Õ¥©¥ë¥È¤Ç 4 ¤Ç¤¢¤Ã¤¿¤Ï¤º¤Ç¤¢¤ë¡£ »þ´Ö¤Ë¥¯¥ê¥Æ¥£¥«¥ë¤Ê¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï ËÜÅö¤ËɬÍפʥե£¡¼¥ë¥É°Ê¾å¤Ëʬ³ä¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤Ù¤¤Ç¤¢¤ë¡£) PATTERN ¤¬³ç¸Ì¤ò´Þ¤ó¤Ç¤¤¤ë¾ì¹ç¡¢ delimiter Ãæ¤Ç¥Þ¥Ã¥Á¤¹¤ëʸ»úÎ󤫤餵¤é¤ËÇÛÎóÍ×ÁǤ¬ºî¤ê½Ð¤µ¤ì¤ë¡£
split(/([,-])/,"1-10,20");¤¬ºî¤ëÇÛÎó¤ÎÃͤÏ
(1,'-',10,',',20)/PATTERN/ ¤Ï¼Â¹Ô»þ¤ËÊѲ½¤¹¤ë¥Ñ¥¿¡¼¥ó¤ò»ØÄꤹ¤ë expression ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£ (¼Â¹Ô»þ¥³¥ó¥Ñ¥¤¥ë¤ò 1 ²ó¤À¤±¹Ô¤¦¤Ë¤Ï¡¢
/$variable/o
¤òÍѤ¤¤ë¡£)
Æüì¤Ê¾ì¹ç¤È¤·¤Æ¡¢¥¹¥Ú¡¼¥¹ (' '
) ¤ò»ØÄꤹ¤ë¤È¡¢
²¿¤â»ØÄꤷ¤Ê¤¤¾ì¹ç¤ÈƱ¤¸¤è¤¦¤Ë white space ¤Çʬ³ä¤¹¤ë¤¬¡¢
ʸ»úÎó¤Î»Ï¤á¤Ë whitespace ¤¬¤¢¤Ã¤Æ¤â°ìÈÖÌܤ˥̥ë¥Õ¥£¡¼¥ë¥É¤òºî¤é¤Ê¤¤¡£
¤¹¤Ê¤ï¤Á¡¢
split(' ')
¤Ï awk ¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤ò¥¨¥ß¥å¥ì¡¼¥È¤¹¤ë¤Î¤Ë»È¤¨¤ë¡£
¤·¤«¤·¡¢
split(/ /)
¤Ïʸ»úÎó¤ÎºÇ½é¤Î¥¹¥Ú¡¼¥¹¤Î¿ô¤À¤±¥Ì¥ë¥Õ¥£¡¼¥ë¥É¤¬ÆÀ¤é¤ì¤ë¡£
open(passwd, '/etc/passwd'); while (<passwd>) { ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/); ... }Ãí°Õ: ¾å¤ÎÎã¤Ç
$shell
¤Ï²þ¹Ôʸ»ú¤ò´Þ¤à¡£chop
¤ò»²¾È¡£join
¤â»²¾È¤Î¤³¤È¡£
See section chop, ¤ª¤è¤Ó See section join.
shift
¤Þ¤¿¤Ï push
¤ÎµÕ¤ò¹Ô¤¦¡£
LIST ¤ò ARRAY ¤ÎÁ°¤ËÉÕ¤±¡¢¤Ç¤¤¿ÇÛÎó¤ÎÍ×ÁÇ¿ô¤òÊÖ¤¹¡£
unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/;See section shift, ¤ª¤è¤Ó See section push.
keys()
¤ä each()
´Ø¿ô¤¬Æ±¤¸ÇÛÎó¤ËÂФ·¤ÆÊÖ¤¹¤â¤Î¤ÈƱ¤¸½ç½ø¤Ç¤¢¤ë¡£
See section each, ¤ª¤è¤Ó See section keys.
$cnt = chmod 0755, 'foo', 'bar'; chmod 0755, @executables;
$cnt = chown $uid, $gid, 'foo', 'bar'; chown $uid, $gid, @filenames; (Îã: passwd ¥Õ¥¡¥¤¥ë¤«¤é¿ôÃͤǤʤ¤ uid ¤ò¸¡º÷¤¹¤ë) print "User: "; $user = <STDIN>; chop($user); print "Files: " $pattern = <STDIN>; chop($pattern); open(pass, '/etc/passwd') || die "Can't open passwd: $!\n"; while (<pass>) { ($login,$pass,$uid,$gid) = split(/:/); $uid{$login} = $uid; $gid{$login} = $gid; } @ary = <${pattern}>; # ¥Õ¥¡¥¤¥ë̾¤òÆÀ¤ë if ($uid{$user} eq ") { die "$user not in passwd file"; } else { chown $uid{$user}, $gid{$user}, @ary; }
stat()
´Ø¿ô¤ÈƱ¤¸¤³¤È¤ò¤¹¤ë¤¬¡¢
¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤¬»Ø¤¹¥Õ¥¡¥¤¥ë¤Ç¤Ï¤Ê¤¯¡¢
¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤½¤Î¤â¤Î¤Î stat
¤òÊÖ¤¹¡£
¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
stat
¤ÈƱ¤¸¤Ç¤¢¤ë¡£
See section stat.
$!
¤ò¥»¥Ã¥È¤¹¤ë(errno)¡£
$!
¤ò¥»¥Ã¥È¤¹¤ë(errno)¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢$_
¤òÍѤ¤¤ë¡£
$!
(errno) ¤ò¥»¥Ã¥È¤¹¤ë¡£
FILENAME ¤ò¾Êά¤¹¤ë¤È¡¢$_
¤òÍѤ¤¤ë¡£
select
¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òÊÖ¤¹¡£
FILEHANDLE ¤ò»ØÄꤹ¤ì¤Ð½ÐÎϤΥǥե©¥ë¥È¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò¥»¥Ã¥È¤¹¤ë¡£
¤³¤ì¤Ë¤ÏÆó¤Ä¤Î¸ú²Ì¤¬¤¢¤ë¡£
write
¤Þ¤¿¤Ï print
¤ò¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ê¤·¤ÇÍѤ¤¤ë¤È¡¢
¥Ç¥Õ¥©¥ë¥È¤Î¤³¤Î FILEHANDLE ¤¬ÍѤ¤¤é¤ì¤ë¡£
¤Þ¤¿¡¢½ÐÎϤ˴ØÏ¢¤Å¤±¤é¤ì¤¿ÊÑ¿ô¤Ø¤Î»²¾È¤Ï¡¢
¤³¤Î(select
¤Ç»ØÄꤷ¤¿)½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤ò»²¾È¤¹¤ë¡£
Î㤨¤Ð¡¢
1 °Ê¾å¤Î½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Ë¤Ä¤¤¤Æ¥Õ¥©¡¼¥Þ¥Ã¥È¤ÎÀèƬ¹Ô¤ò¥»¥Ã¥È¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤»þ¤Ï¡¢
select(REPORT1); $^ = 'report1_top'; select(REPORT2); $^ = 'report2_top';¤Î¤è¤¦¤Ë¤¹¤ì¤Ð¤è¤¤¡£ FILEHANDLE ¤Ï¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤òÃͤȤ·¤Æ»ý¤Ä expression¤Ç¤â¤è¤¤¡£ ¤·¤¿¤¬¤Ã¤Æ¡¢°Ê²¼¤Î¤è¤¦¤Ë»È¤¨¤ë¡£
$oldfh = select(STDERR); $| = 1; select($oldfh);
select
¤ò¥³¡¼¥ë¤¹¤ë¡£
¥Ó¥Ã¥È¥Þ¥¹¥¯¤Ï fileno()
¤È vec()
¤òÍѤ¤¤Æ
°Ê²¼¤Î¤è¤¦¤Ë¤·¤ÆÆÀ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
$rin = $win = $ein = "; vec($rin,fileno(STDIN),1) = 1; vec($win,fileno(STDOUT),1) = 1; $ein = $rin | $win;¿¤¯¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò
select
¤·¤¿¤¤»þ¤Ï
¥µ¥Ö¥ë¡¼¥Á¥ó¤ò½ñ¤¤¤¿Êý¤¬¤¤¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
sub fhbits { local(@fhlist) = split(' ',$_[0]); local($bits); for (@fhlist) { vec($bits,fileno($_),1) = 1; } $bits; } $rin = &fhbits('STDIN TTY SOCK');Ä̾ï¤Î»È¤¤Êý¤Ï¡¢
($nfound,$timeleft) = select($rout=$rin, $wout=$win, $eout=$ein, $timeout);¤Þ¤¿¤Ï²¿¤«¤¬ ready ¤Ë¤Ê¤ë¤Þ¤Ç¥Ö¥í¥Ã¥¯¤¹¤ë¤Ë¤Ï¡¢
$nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);¤Ç¤¢¤ë¡£ ¥Ó¥Ã¥È¥Þ¥¹¥¯¤Ï¤¤¤º¤ì¤â
undef
¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
TIMEOUT ¤ò»ØÄꤹ¤ë»þ¤ÏÉÃñ°Ì¤Ç¡¢¾®¿ôÅÀ¤â²Äǽ¤Ç¤¢¤ë¡£
Ãí°Õ:
¥¤¥ó¥×¥ê¥á¥ó¥È¤Ë¤è¤Ã¤Æ¤Ï$timeleft
¤òÊÖ¤¹µ¡Ç½¤ÏÍøÍѤǤ¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¡£ ¤½¤Î¾ì¹ç¤Ï¾ï¤Ë»ØÄꤷ¤¿$timeout
¤ÈƱ¤¸ÃͤÇ$timeleft
¤¬Ê֤롣
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);
stat
¤ËÆüì¤Ê¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¤·¤Æ¥¢¥ó¥À¡¼¥é¥¤¥ó¤ò»ØÄꤹ¤ë¤È¡¢
stat
¤ò¹Ô¤ï¤º¡¢
ºÇ¸å¤Î stat
¤Þ¤¿¤Ï
¥Õ¥¡¥¤¥ë¥Æ¥¹¥È¤Î·ë²Ì¤Ç¤¢¤ë stat
¹½Â¤ÂΤÎÆâÍƤòÊÖ¤¹¡£
if (-x $file && (($d) = stat(_)) && $d < 0) { print "$file is executable NFS file\n"; }(¤³¤ÎÎã¤Ï NFS ¤Î¥Ç¥Ð¥¤¥¹Èֹ椬Éé¤Ë¤Ê¤ë¤è¤¦¤Ê¥Þ¥·¥ó¤Ç¤Î¤ßÆ°ºî¤¹¤ë¡£)
eval
¤òÍѤ¤¤ë¡£
$symlink_exists = (eval 'symlink("","");', $@ eq ");
truncate
¤¬¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤ÐÃ×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£
$cnt = unlink 'a', 'b', 'c'; unlink @goners; unlink <*.bak>;Ãí°Õ:
unlink
¤Ï¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¤¢¤Ã¤Æ
¤«¤Ä perl ¤Ë -U
¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¤¤¤Ê¤¤¤«¤®¤ê¥Ç¥£¥ì¥¯¥È¥ê¤Ï¾Ãµî¤·¤Ê¤¤¡£
¤³¤ì¤é¤Î¾ò·ï¤Ë¤¢¤Æ¤Ï¤Þ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ç¤â¡¢
¥Ç¥£¥ì¥¯¥È¥ê¤ò unlink
¤¹¤ë¤³¤È¤Ï
¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ë¥À¥á¡¼¥¸¤òÍ¿¤¨¤ë¤³¤È¤ËÃí°Õ¤»¤è¡£
¤«¤ï¤ê¤Ë rmdir
¤ò»È¤¦¤³¤È¡£#!/usr/bin/perl $now = time; utime $now, $now, @ARGV;
opendir()
¤Ç open
¤µ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê¤ò close
¤¹¤ë¡£
open
¤·¡¢
readdir()
¡¢telldir()
¡¢seekdir()
¡¢rewinddir()
¡¢closedir()
¤ò²Äǽ¤Ë¤¹¤ë¡£
À®¸ù¤¹¤ì¤Ð true ¤òÊÖ¤¹¡£opendir()
¤Ç¥ª¡¼¥×¥ó¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Î¼¡¤Î¥¨¥ó¥È¥ê¤òÊÖ¤¹¡£
ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤ÇÍѤ¤¤ë¤È¡¢¥Ç¥£¥ì¥¯¥È¥ê¤Î»Ä¤ê¤Î¥¨¥ó¥È¥ê¤òÁ´¤ÆÊÖ¤¹¡£
¥¨¥ó¥È¥ê¤¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï undefined value¡¢
ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¥Ì¥ë¥ê¥¹¥È¤òÊÖ¤¹¡£readdir()
¤ÇÍѤ¤¤ë¡¢
DIRHANDLE ¤Î¥«¥ì¥ó¥È°ÌÃÖ¤ò¥Ç¥£¥ì¥¯¥È¥ê¤ÎºÇ½é¤Ë¥»¥Ã¥È¤¹¤ë¡£readdir()
¤ÇÍѤ¤¤ë DIRHANDLE ¤Î¥«¥ì¥ó¥È°ÌÃÖ¤ò¥»¥Ã¥È¤¹¤ë¡£
POS ¤Ïtelldir()
¤¬ÊÖ¤¹ÃͤǤʤ¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
directory compaction ¤Ë¤Ä¤¤¤Æ¤Ï
Âбþ¤¹¤ë¥·¥¹¥Æ¥à¥é¥¤¥Ö¥é¥ê´Ø¿ô¤ÈƱÍͤÎÃí°Õ¤¬É¬ÍפǤ¢¤ë¡£readdir()
¤Î¸½ºß¤Î°ÌÃÖ¤òÊÖ¤¹¡£
¥Ç¥£¥ì¥¯¥È¥ê¤Î¤¢¤ë°ÌÃ֤˥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Ë
¤³¤ÎÃͤò seekdir()
¤Ë»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
directory compaction ¤Ë¤Ä¤¤¤Æ¤Ï
Âбþ¤¹¤ë¥·¥¹¥Æ¥à¥é¥¤¥Ö¥é¥ê¥ë¡¼¥Á¥ó¤ÈƱ¤¸Ãí°Õ¤¬É¬ÍפǤ¢¤ë¡£
°Ê²¼¤Î¹àÌܤÎÀâÌÀ¤Ë¤ª¤±¤ë FILEHANDLE ¤Ï¡¢
open
¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤«¡¢
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤òÃͤ˻ý¤Ä¥¹¥«¥é¡¼ÊÑ¿ô¤Ç¤¢¤ë¡£
open
¤¹¤ë¾ì¹ç¤Ï¡¢
close
¤¹¤ëɬÍפÏ̵¤¤¤¬(open
¤¬ close
¤¹¤ë)¡¢
ÆþÎÏ¥Õ¥¡¥¤¥ë¤ËÂФ·¤ÆÌÀ¼¨Åª¤Ë close
¤ò¹Ô¤¦¤È
¥é¥¤¥ó¥«¥¦¥ó¥¿($.
)¤¬¥ê¥»¥Ã¥È¤µ¤ì¤ë
(open
¤Î¹Ô¤¦ close
¤Ç¤Ï¤½¤¦¤Ê¤é¤Ê¤¤)¡£See section @hbox{@hbox to 1.6em{@tt@$.@hfil} : ºÇ¸å¤ËÆɤ߹þ¤ß¤ò¹Ô¤Ã¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¸½ºß¤Î¹ÔÈÖ¹æ}.
¤Þ¤¿¡¢¥Ñ¥¤¥×¤ò close
¤¹¤ë»þ¤Ë¤Ï
¤½¤Î¥Ñ¥¤¥×¤òÍѤ¤¤Æ¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¥×¥í¥»¥¹¤¬½ª¤ï¤ë¤Î¤òÂÔ¤Ä
(¤¢¤È¤Ç¥Ñ¥¤¥×¤Î½ÐÎϤò¸«¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë)¡£
¥Ñ¥¤¥×¤òÌÀ¼¨Åª¤Ë close
¤¹¤ë¤È¥³¥Þ¥ó¥É¤Î¥¹¥Æ¡¼¥¿¥¹¤¬ $?
¤ËÆþ¤ë¡£
open(OUTPUT, '|sort >foo'); # pipe to sort ... # print stuff to output close OUTPUT; # wait for sort to finish open(INPUT, 'foo'); # get sort's resultsFILEHANDLE ¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤òÃͤȤ·¤Æ»ý¤Ä expression ¤Ç¤â¤¤¤¤¡£
open
¤È°ã¤¤¡¢ºÇ½é¤Î°ú¿ô¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ç¤Ï¤Ê¤¤)¡£
DBNAME ¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î̾Á°¤«¤é
`.dir'¤Þ¤¿¤Ï `.pag' ¤Î³ÈÄ¥»Ò¤ò¤È¤Ã¤¿¤â¤Î¤Ç¤¢¤ë¡£
¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð¡¢
MODE ¤Ç»ØÄꤵ¤ì¤ëÊݸî¥â¡¼¥É¤ÇºîÀ®¤µ¤ì¤ë¡£
¸Å¤¤ dbm ´Ø¿ô¤·¤«¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥·¥¹¥Æ¥à¤Î¾ì¹ç¤Ï¡¢
¥×¥í¥°¥é¥àÃæ¤Ç dbmopen
¤Ï°ì²ó¤·¤«¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
dbm ¤â ndbm ¤â¤Ê¤¤¥·¥¹¥Æ¥à¤Ç dbmopen
¤ò¥³¡¼¥ë¤¹¤ë¤È
Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£
dbmopen
¤ÎÁ°¤ÎÏ¢ÁÛÇÛÎó¤ÎÃͤϼº¤ï¤ì¤ë¡£
dbm ¥Õ¥¡¥¤¥ë¤ÎÃͤΰìÉô¤Ï¥á¥â¥ê¤Ë¥¥ã¥Ã¥·¥å¤µ¤ì¤ë¡£
¤³¤ì¤Ï¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï 64 ¸Ä¤Ç¤¢¤ë¤¬¡¢
dbmopen
¤ËÀèΩ¤Ã¤ÆÏ¢ÁÛÇÛÎó¤Ë¥À¥ß¡¼¤ÎÃͤòÂåÆþ¤¹¤ë¤³¤È¤ÇÁý¤ä¤¹¤³¤È¤¬¤Ç¤¤ë¡£
ɬÍפʤ顢reset
¥³¥Þ¥ó¥É¤Ç¥¥ã¥Ã¥·¥å¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
dbm ¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤ßµö²Ä¤¬¤Ê¤¤¾ì¹ç¡¢
Ï¢ÁÛÇÛÎó¤ÎÃͤòÆɤळ¤È¤Ï¤Ç¤¤Æ¤â¡¢ÂåÆþ¤Ï¤Ç¤¤Ê¤¤¡£
½ñ¤¹þ¤ß¤¬¤Ç¤¤ë¤«¤É¤¦¤«¥Æ¥¹¥È¤¹¤ë¤Î¤Ê¤é¡¢¥Õ¥¡¥¤¥ë¥Æ¥¹¥È¤ò»È¤¦¤«¡¢
eval
Ãæ¤Ç¥À¥ß¡¼¤ÎÇÛÎó¤ò¥»¥Ã¥È¤·¤Æ¤ß¤Æ¡¢
¥¨¥é¡¼¤¬µ¯¤³¤ë¤«¤É¤¦¤«¤ÇȽÃǤ¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
Âç¤¤Ê dbm ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¡¢
keys()
¤ä values()
¤È¤¤¤Ã¤¿´Ø¿ô¤ÏµðÂç¤ÊÇÛÎó¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë¡£
each()
¤òÍѤ¤¤Æ
Âç¤¤Ê dbm ¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ·«¤êÊÖ¤·¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¤Ï¡¢¼¡¤ÎÎã¤ò»²¾È¡£
# ¥Ò¥¹¥È¥ê¡¼¥Õ¥¡¥¤¥ë¤Î¥ª¥Õ¥»¥Ã¥È¤ò½ÐÎÏ dbmopen(HIST,'/usr/lib/news/history',0666); while (($key,$val) = each %HIST) { print $key, ' = ', unpack('L',$val), "\n"; } dbmclose(HIST);
open
¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢1 ¤òÊÖ¤¹¡£
FILEHANDLE ¤Ï ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤òÃͤ˻ý¤Ä expression ¤Ç¤â¤è¤¤¡£
(Ãí°Õ: ¤³¤Î´Ø¿ô¤Ï¼ÂºÝ¤Ë¤Ï 1 ʸ»úÆɤ߹þ¤ó¤Ç¤½¤ì¤ò ungetc ¤¹¤ë¤Î¤Ç¡¢
¥¤¥ó¥¿¥é¥¯¥Æ¥£¥Ö¤Ê¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¤¢¤Þ¤êÍÍѤǤϤʤ¤¡£)
°ú¿ô¤Ê¤·¤Î eof
¤ÏºÇ¸å¤ËÆɤ߹þ¤ó¤À¥Õ¥¡¥¤¥ë¤Î eof ¥¹¥Æ¡¼¥¿¥¹¤òÊÖ¤¹¡£
¶õ¤Î³ç¸Ì ()
¤Ï¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ç»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤«¤éºî¤é¤ì¤ë
µ¼»÷¥Õ¥¡¥¤¥ë¤ò»ØÄꤹ¤ë¤Î¤Ë»È¤ï¤ì¤ë¡£
¨¤Á¡¢eof()
¤Ï while (<>)
¤ÎÃæ¤Ç
ºÇ¸å¤Î¥Õ¥¡¥¤¥ë¤Î½ª¤ï¤ê¤ò¸¡½Ð¤¹¤ë¤¿¤á¤Ë»È¤¦»þ¤Î¤ß°ÕÌ£¤¬¤¢¤ë¡£
while (<>)
¥ë¡¼¥×¤ÎÁ´¤Æ¤Î¥Õ¥¡¥¤¥ë¤Î½ª¤ï¤ê¸¡½Ð¤Î¤¿¤á¤Ë¤Ï¡¢
eof(ARGV)
¤« ³ç¸Ì¤Î¤Ê¤¤ eof
¤ò»È¤¦¤Ù¤¤Ç¤¢¤ë¡£
# ºÇ¸å¤Î¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Î 1 ¹ÔÁ°¤Ë¥À¥Ã¥·¥å¤òÆþ¤ì¤ë while (<>) { if (eof()) { print "--------------\n"; } print; } # ³ÆÆþÎÏ¥Õ¥¡¥¤¥ë¤´¤È¤Ë¹ÔÈÖ¹æ¤ò¥ê¥»¥Ã¥È¤¹¤ë while (<>) { print "$.\t$_"; if (eof) { # eof() ¤Ç¤Ï¤Ê¤¤¡£ close(ARGV); } }
require "fcntl.ph"; # ¤¿¤Ö¤ó /usr/local/lib/perl/fcntl.ph¤òºÇ½é¤Ë¹Ô¤¦É¬Íפ¬¤¢¤ë¤À¤í¤¦¡£ `fcntl.ph' ¤¬¤Ê¤«¤Ã¤¿¤êÀµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
ioctl
¤ÈÁ´¤¯Æ±¤¸¤Ç¤¢¤ë¡£
Ãí°Õ: fcntl(2) ¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥Þ¥·¥ó¤Ç»ÈÍѤ¹¤ë¤È
Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£select()
¤Î¥Ó¥Ã¥È¥Þ¥Ã¥×¤ò¹½ÃÛ¤¹¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
FILEHANDLE ¤¬ expression ¤Î¾ì¹ç¤Ï¡¢
¤½¤ÎÃͤ¬¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤Ç¤¢¤ë¤È²ò¼á¤µ¤ì¤ë¡£$LOCK_SH = 1; $LOCK_EX = 2; $LOCK_NB = 4; $LOCK_UN = 8; sub lock { flock(MBOX,$LOCK_EX); # ¤½¤·¤Æ¡¢ÂԤäƤ¤¤ë´Ö¤Ë狼¤¬Äɲ乤ë¾ì¹ç¤ËÈ÷¤¨¤Æ... seek(MBOX, 0, 2); } sub unlock { flock(MBOX,$LOCK_UN); } open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}") || die "Can't open mailbox: $!"; do lock(); print MBOX $msg,"\n\n"; do unlock();
STDIN
¤«¤éÆɤࡣrequire "ioctl.ph"; # probably /usr/local/lib/perl/ioctl.ph¤òºÇ½é¤Ë¹Ô¤¦É¬Íפ¬¤¢¤ë¤À¤í¤¦¡£ `ioctl.ph' ¤¬¤Ê¤«¤Ã¤¿¤êÀµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
ioctl()
¤Ç»ÈÍѤµ¤ì¤ë¹½Â¤ÂΤÎÃͤòÁàºî¤¹¤ë¤Ë¤Ï¡¢
pack()
¤ä unpack()
´Ø¿ô¤¬ÊØÍø¤Ç¤¢¤ë¡£
¼¡¤ÎÎã¤Ç¤Ï¡¢erase character ¤ò DEL ¤Ë¥»¥Ã¥È¤¹¤ë¡£
do 'ioctl.ph'; $sgttyb_t = "ccccs"; # char 4 ¤Ä¤È short if (ioctl(STDIN,$TIOCGETP,$sgttyb)) { @ary = unpack($sgttyb_t,$sgttyb); $ary[2] = 127; $sgttyb = pack($sgttyb_t,@ary); ioctl(STDIN,$TIOCSETP,$sgttyb) || die "Can't ioctl: $!"; }
ioctl
(¤ª¤è¤Ó fcntl
)¤ÎÊÖ¤êÃͤϼ¡¤Î¤è¤¦¤Ë¤Ê¤ë¡£
OS ¤ÎÊÖ¤êÃÍ: perl ¤ÎÊÖ¤êÃÍ -1 undefined value 0 string `0 but true' ¤½¤ì°Ê³° ¤½¤ÎÃͤĤޤꡢperl ¤ÏÀ®¸ù¤¹¤ì¤Ð¿¿¡¢¼ºÇÔ¤¹¤ì¤Ðµ¶¤òÊÖ¤¹¤¬¡¢ OS ¤¬ÊÖ¤¹¼ÂºÝ¤ÎÃͤò´Êñ¤ËÆÀ¤ë¤³¤È¤â¤Ç¤¤ë¡£
($retval = ioctl(...)) || ($retval = -1); printf "System returned %d\n", $retval;
open
¤·¡¢
FILEHANDLE ¤È·ë¤ÓÉÕ¤±¤ë¡£
FILEHANDLE ¤¬ expression ¤Î¾ì¹ç¤Ï¡¢
¤½¤ÎÃͤ¬¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î̾Á°¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
EXPR ¤ò¾Êά¤·¤¿¾ì¹ç¡¢
FILEHANDLE ¤ÈƱ̾¤Î¥¹¥«¥é¡¼ÊÑ¿ô¤¬¥Õ¥¡¥¤¥ë̾¤ò»ý¤Ä¡£
open
¤µ¤ì¤ë¡£open
¤µ¤ì¤ë¡£
open
¤µ¤ì¤ë¡£
STDIN
¤ò open
¤·¡¢
`>-' ¤Ï STDOUT
¤ò open
¤¹¤ë¡£open
¤¬¥Ñ¥¤¥×¤ò´Þ¤à¾ì¹ç¡¢ÊÖ¤êÃͤϥµ¥Ö¥×¥í¥»¥¹¤Î pid ¤Ë¤Ê¤ë¡£
$article = 100; open article || die "Can't find article $article: $!\n"; while (<article>) { ... open(LOG, '>>/usr/spool/news/twitlog'); # (log ¤ÏͽÌó¸ì¤Ç¤¢¤ë) open(article, "caesar <$article |"); # µ»ö¤ò decrypt ¤¹¤ë open(extract, "|sort >/tmp/Tmp$$"); # $$ ¤Ï¸½ºß¤Î¥×¥í¥»¥¹ # # °ú¿ô¤Î¥Õ¥¡¥¤¥ë¥ê¥¹¥È¤Ë¤Ä¤¤¤Æ # ¤½¤ì¤¬¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¥Õ¥¡¥¤¥ë¤â´Þ¤á¤Æ½èÍý¤¹¤ë foreach $file (@ARGV) { do process($file, 'fh00'); # no pun intended } sub process { local($filename, $input) = @_; $input++; # ¤³¤ì¤Ïʸ»úÎó¤Î¥¤¥ó¥¯¥ê¥á¥ó¥È¤Ç¤¢¤ë unless (open($input, $filename)) { print STDERR "Can't open $filename: $!\n"; return; } while (<$input>) { # ´ÖÀÜ»ØÄê¤ËÃí°Õ if (/^#include "(.*)"/) { do process($1, $input); next; } ... # whatever } }Bourne shell ¤Î´·½¬¤Ç¡¢EXPR ¤ò `>&' ¤Ç»Ï¤á¤Æ¤âÎɤ¤¡£ ¤³¤Î¾ì¹ç¡¢»Ä¤ê¤Îʸ»úÎó¤Ï ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë (¤Þ¤¿¤Ï¿ôÃͤʤé¤Ð ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿)¤È²ò¼á¤µ¤ì¡¢
dup
¤µ¤ì¡¢open
¤µ¤ì¤ë¡£
`&' ¤Ï `>', `>>', `<',
`+>', `+>>', `+<' ¤Î¸å¤ÇÍѤ¤¤ÆÎɤ¤¡£
»ØÄꤹ¤ë¥â¡¼¥É¤Ï¸µ¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ÈƱ¤¸¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
°Ê²¼¤Î¥¹¥¯¥ê¥×¥È¤Ï STDOUT
¤ª¤è¤Ó STDERR
¤òÊݸ¤·¡¢
¥ê¥À¥¤¥ì¥¯¥È¤·¡¢¸µ¤ËÌ᤹¡£
#!/usr/bin/perl open(SAVEOUT, ">&STDOUT"); open(SAVEERR, ">&STDERR"); open(STDOUT, ">foo.out") || die "Can't redirect stdout"; open(STDERR, ">&STDOUT") || die "Can't dup stdout"; select(STDERR); $| = 1; # ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤Ê¤·¤Ë¤¹¤ë select(STDOUT); $| = 1; # ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤Ê¤·¤Ë¤¹¤ë print STDOUT "stdout 1\n"; # ¤³¤ì¤Ï¥µ¥Ö¥×¥í¥»¥¹¤Ç¤â print STDERR "stderr 1\n"; # Ư¤¯ close(STDOUT); close(STDERR); open(STDOUT, ">&SAVEOUT"); open(STDERR, ">&SAVEERR"); print STDOUT "stdout 2\n"; print STDERR "stderr 2\n";¥³¥Þ¥ó¥É `-' ¤òÍѤ¤¤Æ¥Ñ¥¤¥×¤ò
open
¤¹¤ë¾ì¹ç¡¢
¤¹¤Ê¤ï¤Á `|-' ¤Þ¤¿¤Ï`-|' ¤Î¾ì¹ç¡¢
°ÅÌÛ¤ÎÆâ¤Ë fork
¤¬¤Ê¤µ¤ì¡¢
open
¤ÎÊÖ¤êÃÍ¤Ï¿Æ¥×¥í¥»¥¹¤Ç¤Ï»Ò¥×¥í¥»¥¹¤Î pid¡¢
»Ò¥×¥í¥»¥¹¤Ç¤Ï 0 ¤Ë¤Ê¤ë¡£
(open
¤¬À®¸ù¤·¤¿¤«¤É¤¦¤«¤Ï defined($pid)
¤Ç³Î¤«¤á¤ë¡£)
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ÎµóÆ°¤Ï¿Æ¥×¥í¥»¥¹¤Ç¤ÏÄ̾ï¤ÈƱ¤¸¤Ç¤¢¤ë¤¬¡¢
¤½¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ø¤Î i/o ¤Ï
»Ò¥×¥í¥»¥¹¤Î STDOUT
/STDIN
¤Ë¥Ñ¥¤¥×¤µ¤ì¤ë¡£
»Ò¥×¥í¥»¥¹¤Ç¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï open
¤µ¤ì¤Æ¤¤¤Ê¤¤ ---
i/o ¤Ï¿·¤¿¤Ê STDOUT
¤«¤é/STDIN
¤Ë ¤Ê¤µ¤ì¤ë¡£
Îɤ¯»È¤ï¤ì¤ë¤Î¤Ï¡¢Î㤨¤Ð setuid ¤ÇÁö¤é¤»¤Æ¤¤¤ë¤È¤¤Ê¤É¡¢
¥Ñ¥¤¥×¥³¥Þ¥ó¥É¤Î¼Â¹Ô¾õÂÖ¤ò¥³¥ó¥È¥í¡¼¥ë¤·¤¿¤¤»þ¤ä¡¢
¥·¥§¥ë¥³¥Þ¥ó¥É¤Ë¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤¬¤¢¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤·¤¿¤¯¤Ê¤¤»þ¤Ç¤¢¤ë¡£
¼¡¤Î 2 ¤Ä¤Î¥Ú¥¢¤Ï¤½¤ì¤¾¤ì¤¢¤ëÄøÅÙ(more or less)ƱÅù¤Ç¤¢¤ë¡£
open(FOO, "|tr '[a-z]' '[A-Z]'"); open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]'; open(FOO, "cat -n '$file'|"); open(FOO, "-|") || exec 'cat', '-n', $file;ÌÀ¼¨Åª¤Ë¥Ñ¥¤¥×¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò
close
¤¹¤ë¤È
¿Æ¥×¥í¥»¥¹¤Ï»Ò¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¤Î¤òÂÔ¤Á¡¢¥¹¥Æ¡¼¥¿¥¹ÃÍ $?
¤¬ÊÖ¤êÃͤȤʤ롣
Ãí°Õ:fork
¤ò¹Ô¤¦Áàºî¤Ë¤ª¤¤¤Æ¤Ï¡¢
¥Õ¥é¥Ã¥·¥å¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ð¥Ã¥Õ¥¡¤ÏξÊý¤Î¥×¥í¥»¥¹¤Ë¤ª¤¤¤Æ¥Õ¥é¥Ã¥·¥å¤µ¤ì¤º¤Ë»Ä¤ë¡£
¤Ä¤Þ¤ê¡¢Æó½Å¤Ë½ÐÎϤµ¤ì¤ë¤Î¤òÈò¤±¤ë¤Ë¤Ï¡¢
$|
¤ò¥»¥Ã¥È¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
See section @hbox{@hbox to 1.6em{@tt@$|@hfil} : write ¤Þ¤¿¤Ï print ¤Î¸å¤Ë¥Õ¥é¥Ã¥·¥å¤ò¹Ô¤¦¤«Èݤ«}.
open
¤ËÅϤµ¤ì¤ë¥Õ¥¡¥¤¥ë̾¤ÏºÇ½é¤äºÇ¸å¤Î¥¹¥Ú¡¼¥¹¤ò¼è¤ê½ü¤«¤ì¤ë¡£
̾Á°¤Ë¤ª¤«¤·¤Êʸ»ú¤¬´Þ¤Þ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò open
¤¹¤ë¤Ë¤Ï¡¢
¼¡¤Î¤è¤¦¤Ë¤·¤ÆÁ°¸å¤Î¥¹¥Ú¡¼¥¹¤¬¼è¤ê½ü¤«¤ì¤Ê¤¤¤è¤¦¤Ë¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
$file =~ s#^(\s)#./$1#; open(FOO, "< $file\0");
$|
¤ò¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
See section @hbox{@hbox to 1.6em{@tt@$|@hfil} : write ¤Þ¤¿¤Ï print ¤Î¸å¤Ë¥Õ¥é¥Ã¥·¥å¤ò¹Ô¤¦¤«Èݤ«}.
[perl 3.0 ¥Ñ¥Ã¥Á¥ì¥Ù¥ë 9 °Ê¾å¤¬É¬Íס£]
+
¤òÆþ¤ì¤ë¤«¡¢
°ú¿ô¤Ë³ç¸Ì¤ò¤Ä¤±¤ë¤«¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£)
FILEHANDLE ¤ò¾Êά¤¹¤ë¤È¡¢
¥Ç¥Õ¥©¥ë¥È¤Ç¤Ïɸ½à½ÐÎÏ(¤Þ¤¿¤ÏºÇ¸å¤Ë select
¤µ¤ì¤¿½ÐÎÏ¥Á¥ã¥ó¥Í¥ë ---
select()
»²¾È See section select.)¤Ë½ÐÎϤ¹¤ë¡£
LIST ¤â¾Êά¤¹¤ë¤È¡¢$_
¤ò STDOUT
¤Ë½ÐÎϤ¹¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Î½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤ò STDOUT
°Ê³°¤Î¤â¤Î¤Ë¤¹¤ë¤Ë¤Ï¡¢
select
±é»»»Ò¤ò»ÈÍѤ¹¤ë¡£
Ãí°Õ:print
¤Ï¥ê¥¹¥È¤ò°ú¿ô¤Ë¼è¤ë¤Î¤Ç¡¢
LIST ¤ÎÍ×ÁǤÏÁ´¤ÆÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤µ¤ì¡¢
¤Þ¤¿¥µ¥Ö¥ë¡¼¥Á¥ó¤ò¥³¡¼¥ë¤¹¤ë¤È
¤½¤Î 1 ¤Ä°Ê¾å¤Î expression ¤ÏÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Çɾ²Á¤µ¤ì¤ë¡£?
¤Þ¤¿¡¢¥¡¼¥ï¡¼¥É print
¤Î¸å¤Ëº¸³ç¸Ì¤Ï¤Ä¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤¹¤ëɬÍפ¬¤¢¤ë
(print
¤Ø¤Î°ú¿ô¤ò¶èÀÚ¤ë ---
+
¤ò´Ö¤ËÆþ¤ì¤ë¤«Á´°ú¿ô¤ò³ç¸Ì¤Ç°Ï¤à ---
¤¿¤á¤ËÂбþ¤·¤¿±¦³ç¸Ì¤ò¤Ä¤±¤¿¤¤¾ì¹ç¤ò½ü¤¤¤Æ)¡£print FILEHANDLE sprintf(LIST)
¤ÈƱÅù¤Ç¤¢¤ë¡£
See section print, ¤ª¤è¤Ó See section sprintf.
sysread
¤ò»²¾È¤»¤è¡£See section sysread.printf
¤Î½¬´·¤Ç¥Õ¥©¡¼¥Þ¥Ã¥È¤µ¤ì¤¿Ê¸»úÎó¤òÊÖ¤¹¡£print
¤È°ì½ï¤Ë»È¤¦¤Èº®Í𤹤뤳¤È¤¬¤¢¤ë¡£
¼ÂºÝ¤Ë½ñ¤¹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¤¢¤Ã¤¿¾ì¹ç¤Ï undef ¤òÊÖ¤¹¡£
½ñ¤¹þ¤à¥Ç¡¼¥¿¤òʸ»úÎó¤ÎÀèƬ¤«¤é¤Ç¤Ï¤Ê¤¯Ê̤ΰÌÃÖ¤«¤é¼è¤ê½Ð¤¹¤¿¤á¤Ë¡¢
OFFSET ¤ò»ØÄꤷ¤Æ¤â¤è¤¤¡£select
»²¾È)¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï
¥Õ¥©¡¼¥Þ¥Ã¥È¤Î̾Á°¤ò $~
¤Ë»ØÄꤹ¤ë¤³¤È¤ÇÌÀ¼¨¤Ç¤¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$~@hfil} : ½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¸½ºß¤Î¥ì¥Ý¡¼¥È¥Õ¥©¡¼¥Þ¥Ã¥È̾}.
À°·ÁÁàºî¤Ï¼«Æ°Åª¤Ë¹Ô¤ï¤ì¤ë¡£
¸½ºß¤Î¥Ú¡¼¥¸¤Ë¥Õ¥©¡¼¥Þ¥Ã¥È¤·¤¿¥ì¥³¡¼¥É¤ËÂФ·¤Æ½¼Ê¬¤Ê;͵¤¬¤Ê¤¤¾ì¹ç¤Ï
²þÊǤò½ÐÎϤ·¤Æ¼¡¤Î¥Ú¡¼¥¸¤Ë°Ü¤ê¡¢
¿·¤·¤¤¥Ú¡¼¥¸¤Î¥Ø¥Ã¥À¡¼¤ò¥Õ¥©¡¼¥Þ¥Ã¥È¤¹¤ë¤Ë¤Ï
Æüì¤Ê¥Ú¡¼¥¸ÀèƬ¥Õ¥©¡¼¥Þ¥Ã¥È¤¬»È¤ï¤ì¡¢
¤³¤¦¤·¤Æ¥ì¥³¡¼¥É¤¬½ÐÎϤµ¤ì¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥Ú¡¼¥¸ÀèƬ¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë̾¤Ë "_TOP
" ¤ò¤Ä¤±¤¿¤â¤Î¤Ç¤¢¤ë¤¬¡¢
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ select
¤µ¤ì¤Æ¤¤¤ë»þ¤Ë $^
¤ËÂåÆþ¤¹¤ë¤³¤È¤Ç
¹¥¤ß¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ËưŪ¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$^@hfil} : ½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¸½ºß¤Î¥Ú¡¼¥¸¥È¥Ã¥×̾}.
¸½ºß¤Î¥Ú¡¼¥¸¤Ë»Ä¤Ã¤Æ¤¤¤ë¹Ô¿ô¤ÏÊÑ¿ô $-
¤ËÆþ¤Ã¤Æ¤ª¤ê¡¢
¤³¤ì¤ò 0 ¤Ë¥»¥Ã¥È¤·¤Æ¶¯À©Åª¤Ë¿·¤·¤¤¥Ú¡¼¥¸¤ËÆþ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
FILEHANDLE ¤ò»ØÄꤷ¤Ê¤¤¾ì¹ç¤Ï¡¢
½ÐÎϤϸ½ºß¤Î¥Ç¥Õ¥©¥ë¥È½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Ë¤Ê¤µ¤ì¤ë¡£
¤³¤ì¤ÏºÇ½é¤Ï STDOUT
¤Ç¡¢select
¤òÍѤ¤¤ÆÊѹ¹²Äǽ¤Ç¤¢¤ë¡£
FILEHANDLE ¤¬ expression ¤Î¾ì¹ç¤Ï¡¢¼Â¹Ô»þ¤Ë expression ¤¬É¾²Á¤µ¤ì¡¢
¤½¤Î·ë²Ì¤Îʸ»úÎó¤¬ FILEHANDLE ¤Î̾Á°¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
format
¤Ë¤Ä¤¤¤Æ¤Î¾ÜºÙ¤Ï¡¢¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¾Ï¤ò»²¾È¤Î¤³¤È¡£write
¤Ï read
¤ÎÈ¿ÂФǤϤʤ¤¡£
"
)¤òÊÖ¤¹¡£
=~
¤ä !~
¤Çʸ»úÎó¤ò»ØÄꤷ¤Ê¤¤¾ì¹ç¤Ï $_
ʸ»úÎó¤ò¸¡º÷¤¹¤ë¡£
(=~
¤Ç»ØÄꤵ¤ì¤ëʸ»úÎó¤Ïº¸ÊÕÃͤǤ¢¤ëɬÍפϤʤ¤ ---
expression ɾ²Á¤Î·ë²Ì¤Ç¤âÎɤ¤¤¬¡¢ =~
¤ÎÊý¤¬Í¥ÀèÅÙ¤¬¹â¤¤¤³¤È¤ËÃí°Õ¡£)
Àµµ¬É½¸½¤Î¾Ï¤â»²¾È¤Î¤³¤È¡£
See section Àµµ¬É½¸½.
/
¤¬ delimiter ¤Ç¤¢¤ë¤Ê¤é¡¢ºÇ½é¤Î m
¤Ï¾Êά²Äǽ¤Ç¤¢¤ë¡£
m
¤ò»È¤¦¤È¡¢
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¡¦¿ô»ú¤Ç¤Ê¤¤Ç¤°Õ¤Îʸ»ú¤Î¥Ú¥¢¤ò delimiter ¤È¤·¤Æ»È¤¨¤ë¡£
¤³¤ì¤Ï Unix ¤Î¥Ñ¥¹Ì¾(/
¤ò´Þ¤à)¤Î¥Þ¥Ã¥Á¥ó¥°¤ò¤¹¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
Æó¤ÄÌܤÎdelimiter ¤Î¸å¤Ë¥ª¥×¥·¥ç¥ó i
¤ò¤Ä¤±¤ë¤È¡¢
case insensitive ¤Ç¥Þ¥Ã¥Á¥ó¥°¤ò¹Ô¤¦¡£
PATTERN ¤Ï¥¹¥«¥é¡¼ÊÑ¿ô¤ò´Þ¤ó¤Ç¤¤¤Æ¤âÎɤ¤¤¬¡¢
¥Ñ¥¿¡¼¥ó¸¡º÷¤ò¹Ô¤¦Ëè¤ËÃÖ¤´¹¤¨¤¬¹Ô¤ï¤ì¤ë(¤½¤·¤Æ¥Ñ¥¿¡¼¥ó¤¬ºÆ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë)¡£
(Ãí°Õ: $)
¤È $|
¤Ï
ʸ»úÎó¤Î½ª¤ï¤ê¤Î¥Á¥§¥Ã¥¯¤Ë»È¤ï¤ì¤ë¤Ç¤¢¤í¤¦¤«¤é¡¢
ÃÖ¤´¹¤¨¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£)
¥Ñ¥¿¡¼¥ó¤òºÇ½é¤Î°ì²ó¤À¤±¥³¥ó¥Ñ¥¤¥ë¤µ¤»¤¿¤¤»þ¤Ï¡¢
ºÇ¸å¤Î¥ª¥×¥·¥ç¥ó¤Ë o
¤ò»ØÄꤹ¤ë¡£
¤³¤¦¤¹¤ë¤È¼Â¹Ô»þ¤ÎºÆ¥³¥ó¥Ñ¥¤¥ë¤òÈò¤±¤ë¤³¤È¤¬¤Ç¤¤ë¤Î¤Ç¡¢
ÊÑ¿ô¤ÇÃÖ¤´¹¤¨¤Æ¤¤¤ëÃͤ¬¥¹¥¯¥ê¥×¥È¼Â¹ÔÃæ¤ËÊѤï¤é¤Ê¤¤¤Î¤Ç¤¢¤ì¤Ð¡¢ÊØÍø¤Ç¤¢¤ë¡£
PATTERN ¤¬¥Ì¥ëʸ»úÎó¤Ëɾ²Á¤µ¤ì¤¿¾ì¹ç¡¢
ľÁ°¤ËÀ®¸ù¤·¤¿Àµµ¬É½¸½¤¬Âå¤ï¤ê¤ËÍѤ¤¤é¤ì¤ë¡£
ÇÛÎóÃͤ¬É¬ÍפÊʸ̮¤Ç»È¤¦¤È¡¢¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ï¥Ñ¥¿¡¼¥ó¤ò³ç¸Ì¤Ç¤¯¤¯¤Ã¤¿¤â¤Î¡¢
¤¹¤Ê¤ï¤Á ($1, $2, $3 ...)
¤Ë¥Þ¥Ã¥Á¤¹¤ë subexpression ¤«¤é¤Ê¤ë
ÇÛÎó¤òÊÖ¤¹¡£¼ÂºÝ¤Ë¤Ï $1
¡¢$2
¤Ê¤É¤ò¥»¥Ã¥È¤»¤º¡¢
¤³¤Î¾ì¹ç¤À¤È¡¢$+
¡¢$`
¡¢$&
¡¢$'
¤â¥»¥Ã¥È¤·¤Ê¤¤¡£
¥Þ¥Ã¥Á¥ó¥°¤¬¼ºÇÔ¤·¤¿¾ì¹ç¡¢¥Ì¥ëÇÛÎó¤¬Ê֤롣(1)
¤¬Ê֤롣
open(tty, '/dev/tty'); <tty> =~ /^y/i && do foo(); # y ¤ÈÅú¤¨¤¿¤é do foo if (/Version: *([0-9.]*)/) { $version = $1; } next if m#^/usr/spool/uucp#; # poor man's grep $arg = shift; while (<>) { print if /$arg/o; # 1 ²ó¤À¤±¥³¥ó¥Ñ¥¤¥ë¤¹¤ë } if (($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))ºÇ¸å¤ÎÎã¤Ï¡¢
$foo
¤òÆó¤Ä¤Î word ¤È»Ä¤ê¤Ëʬ¤±¡¢
¤³¤ì¤é»°¤Ä¤Î¥Õ¥£¡¼¥ë¥É¤ò $F1
, $F2
, $Etc
¤ËÂåÆþ¤¹¤ë¡£
¤É¤ÎÊÑ¿ô¤¬Êѹ¹¤µ¤ì¤Æ¤â¡¢¤¹¤Ê¤ï¤Á¡¢¥Ñ¥¿¡¼¥ó¤¬¥Þ¥Ã¥Á¤¹¤ì¤Ð¡¢¾ò·ï¤Ï¿¿¤Ç¤¢¤ë¡£
½¤¾þ»Ò "g"
¤Ï¥°¥í¡¼¥Ð¥ë¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤ò»ØÄꤹ¤ë -- ¤¹¤Ê¤ï¤Á¡¢
ʸ»úÎóÃæ¤Ç²Äǽ¤Ê¤«¤®¤ê¥Þ¥Ã¥Á¤ò¹Ô¤¦¡£
¥³¥ó¥Æ¥¥¹¥È¤Ë¤è¤ê¤É¤Î¤è¤¦¤Ë¿¶Éñ¤¦¤«¡£
ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢
Àµµ¬É½¸½Ãæ¤Î¤¹¤Ù¤Æ¤Î³ç¸Ì¤È¥Þ¥Ã¥Á¤¹¤ë substring ¤«¤é¤Ê¤ë¥ê¥¹¥È¤òÊÖ¤¹¡£
³ç¸Ì¤¬°ì¤Ä¤â¤Ê¤¤¾ì¹ç¡¢¥Ñ¥¿¡¼¥óÁ´ÂΤβó¤ê¤Ë³ç¸Ì¤¬¤¢¤ë¤«¤Î¤è¤¦¤Ë°·¤¤¡¢
¥Þ¥Ã¥Á¤·¤¿Á´Ê¸»úÎó¤Î¥ê¥¹¥È¤òÊÖ¤¹¡£
¥¹¥«¥é¡¼¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢Ê¸»úÎóÁ´ÂΤˤĤ¤¤Æ·«¤êÊÖ¤·¤ò¹Ô¤¤¡¢
¥Þ¥Ã¥Á¤¹¤ëÅÙ¤Ë TRUE ¤òÊÖ¤·¡¢¤Ä¤¤¤Ë¥Þ¥Ã¥Á¤·¤Ê¤¯¤Ê¤Ã¤¿»þÅÀ¤Ç FALSE ¤òÊÖ¤¹¡£
(¸À¤¤Âؤ¨¤ì¤Ð¡¢Á°¤Ë¤É¤³¤Þ¤Ç¥Þ¥Ã¥Á¤ò¹Ô¤Ê¤Ã¤¿¤«¤ò³Ð¤¨¤Æ¤ª¤¡¢
¤½¤Î°ÌÃÖ¤«¤é¸¡º÷¤òºÆ³«¤¹¤ë¡£)
ºÇ¸å¤Î¥Þ¥Ã¥Á¤ò¹Ô¤Ê¤Ã¤Æ¤«¤éʸ»úÎó¤òÊѹ¹¤·¤Æ¤¤¤Ê¤¤¤È¤¤¤¦¤³¤È¤ò²¾Äꤷ¤Æ¤¤¤ë¡£
¥Þ¥Ã¥Á¤Î´Ö¤Çʸ»úÎó¤òÊѹ¹¤¹¤ë¤È̤ÄêµÁ¤ÎÆ°ºî¤ò¹Ô¤¦²ÄǽÀ¤¬¤¢¤ë¡£
(¼Â¤Ï¡¢substr()
¤ò»È¤Ã¤ÆÁ´Ê¸»úÎó¤ÎŤµ¤òÊѤ¨¤Ê¤¤¤Ç
ʸ»úÎó¤ò¤½¤Î¾ì¤Ç(in-place)Êѹ¹¤¹¤ë¾ì¹ç¤Ë¤Ï¤¦¤Þ¤¯¤¤¤¯¡£¤·¤«¤·¡¢°ìÈÌŪ¤Ë¤Ï¡¢
¤½¤Î¤è¤¦¤ÊÊѹ¹¤ò¹Ô¤¦¾ì¹ç¤Ï s//g
¤ò»È¤¦¤Ù¤¤Ç¤¢¤ë¡£)
Îã:
# array context ($one,$five,$fifteen) = (`uptime` =~ /(\d+\.\d+)/g); # scalar context $/ = ""; $* = 1; while ($paragraph = <>) { while ($paragraph =~ /[a-z]['")]*[.!?]+['")]*\s/g) { $sentences++; } } print "$sentences\n";
reset
¤«¤é reset
¤Þ¤Ç¤Ç 1 ²ó¤·¤«¥Þ¥Ã¥Á¤·¤Ê¤¤¤³¤È¤ò½ü¤¤¤Æ¡¢
/¥Ñ¥¿¡¼¥ó/ ¸¡º÷¤ÈƱ¤¸¤Ç¤¢¤ë¡£Î㤨¤Ð¡¢´ö¤Ä¤«¤¢¤ë¥Õ¥¡¥¤¥ë¤Î³Æ¡¹¤Ë¤Ä¤¤¤Æ¡¢
¤¢¤ë¤â¤Î¤¬ºÇ½é¤Ë¸½¤ì¤ë¤Î¤òÄ´¤Ù¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
¸½ºß¤Î¥Ñ¥Ã¥±¡¼¥¸¤Ë¥í¡¼¥«¥ë¤Ê ??
¥Ñ¥¿¡¼¥ó¤Î¤ß¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
See section reset.
""
¤Ç³ç¤é¤ì¤¿Ê¸»úÎó¤Ç¤Ï¤Ê¤¯¡¢
expression ¤È¤·¤Æɾ²Á¤µ¤ì¤ë¡£
¥¹¥é¥Ã¥·¥å¤ÎÂå¤ï¤ê¤Ë
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¡¦¿ô»ú¤Ç¤Ê¤¤Ç¤°Õ¤Îʸ»ú¤ò delimiter ¤È¤·¤Æ¤è¤¤¡£
s(foo)(bar)
¤ä s<foo>/bar/
¡£=~
±é»»»Ò ¤ä !~
±é»»»Ò¤òÄ̤·¤Æʸ»úÎó¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¡¢
$_
¤Ë¤Ä¤¤¤Æ¸¡º÷¤·¡¢ÃÖ´¹¤¹¤ë¡£
(=~
¤òÍѤ¤¤Æ»ØÄꤹ¤ëʸ»úÎó¤Ï¥¹¥«¥é¡¼ÊÑ¿ô¡¢ÇÛÎó¤ÎÍ×ÁÇ¡¢
¤Þ¤¿¤Ï¤³¤ì¤é 2 ¤Ä¤Ø¤ÎÂåÆþ¡¢Â¨¤Á¡¢º¸ÊÕÃͤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£)
PATTERN ¤¬ $
¤ò´Þ¤ß¡¢
"ʸ»úÎóºÇ¸å"¤Ç¤Ï¤Ê¤¯¤Æ"ÊÑ¿ô"¤Ë¸«¤¨¤ë¾ì¹ç¤Ï¡¢
¼Â¹Ô»þ¤Ë¤½¤ÎÊÑ¿ô¤¬ PATTERN ¤Ë½ñ¤¹þ¤Þ¤ì¤ë¡£
¥Ñ¥¿¡¼¥ó¤Î¥³¥ó¥Ñ¥¤¥ë¤òºÇ½é¤Î°ì²ó¤À¤±¤Ë¤·¡¢ÊÑ¿ô¤Î½ñ¤´¹¤¨¤ò¹Ô¤¤¤¿¤¤»þ¤Ï¡¢
`o' ¤òºÇ¸å¤Ë¤Ä¤±¤ë¡£PATTERN ¤¬¥Ì¥ëʸ»úÎó¤Ëɾ²Á¤µ¤ì¤¿¾ì¹ç¡¢
ľÁ°¤ËÀ®¸ù¤·¤¿Àµµ¬É½¸½¤¬Âå¤ï¤ê¤ËÍѤ¤¤é¤ì¤ë¡£Àµµ¬É½¸½¤Î¹à¤ò»²¾È¡£
s/\bgreen\b/mauve/g; # wintergreen ¤ÏÊѹ¹¤·¤Ê¤¤ $path =~ s|/usr/bin|/usr/local/bin|; s/Login: $foo/Login: $bar/; # ¼Â¹Ô»þ¤Ë·è¤Þ¤ë¥Ñ¥¿¡¼¥ó ($foo = $bar) =~ s/bar/foo/; $_ = 'abc123xyz'; s/\d+/$&*2/e; # 'abc246xyz' ¤ò½ÐÎÏ s/\d+/sprintf("%5d",$&)/e; # 'abc 246xyz' ¤ò½ÐÎÏ s/\w/$& x 2/eg; # 'aabbcc 224466xxyyzz' ¤ò½ÐÎÏ s/([^ ]*) *([^ ]*)/$2 $1/; # ºÇ½é¤Î 2 ¥Õ¥£¡¼¥ë¥É¤òÆþ¤ìÂؤ¨Ãí°Õ:
\
¤ÎÂå¤ï¤ê¤Ë $
¤ò»ÈÍѤ·¤Æ¤¤¤ë¤³¤È¤ËÃí°Õ¡£
Àµµ¬É½¸½¤Î¹à¤ò»²¾È¡£
See section Àµµ¬É½¸½.$_
)¤Ë¤Ä¤¤¤Æ¡¢
¤½¤ì¤¬¼¡¤ËÊѹ¹¤µ¤ì¤ëÁ°¤Ë¿¤¯¤Î¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤ò¤¢¤é¤«¤¸¤á¹Ô¤¦¡£
¸¡º÷¤ò¹Ô¤¦¥Ñ¥¿¡¼¥ó¤ÎÀ¼Á¤ä¿ô¡¢¸¡º÷¤µ¤ì¤ëʸ»úÎóÃæ¤Îʸ»ú¤ÎÉÑÅÙʬÉۤˤè¤ê
»þ´Ö¤¬ÀáÌ󤵤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¤·¡¢¤µ¤ì¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
¿ʬ¤³¤ì¤ò»ÈÍѤ¹¤ë¤Î¤È¤·¤Ê¤¤¤Î¤È¡¢
¤É¤Á¤é¤¬Á᤯¼Â¹Ô¤Ç¤¤ë¤«¤òÈæ³Ó¤·¤Æ¤ß¤¿¤¤¤Ç¤¢¤í¤¦¡£
¿ô¿¤¯¤Îû¤¤Äê¿ôʸ»úÎó(¤è¤êÊ£»¨¤Ê¥Ñ¥¿¡¼¥óÃæ¤ÎÄê¿ôÉô¤ò´Þ¤à)¤Ë¤Ä¤¤¤Æ
¸¡º÷¤ò¹Ô¤¦¥ë¡¼¥×¤Ë¤ª¤¤¤ÆºÇ¤â¸ú²Ì¤¬¤¢¤ë¤À¤í¤¦¡£
Ʊ»þ¤Ë 1 ¤Ä¤·¤« study
¤Ç¤¤Ê¤¤¡£
Ê̤Υ¹¥«¥é¡¼¤ò study
¤¹¤ë¤È¡¢
ºÇ½é¤Ë study
¤·¤¿Êý¤Ï unstudied ¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¡£
(study
¤ÎÆ°ºî¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ë:
¸¡º÷ÂоݤÎʸ»úÎó¤ÎÁ´Ê¸»ú¤Î linked list ¤òºî¤ê¡¢¤³¤ì¤Ë¤è¤ê¡¢Î㤨¤Ð¡¢
Á´¤Æ¤Î `k' ¤È¤¤¤¦Ê¸»ú¤¬¤É¤³¤Ë¤¢¤ë¤«¤¬¤ï¤«¤ë¡£
C ¥×¥í¥°¥é¥à¤ª¤è¤Ó±Ñʸ¤«¤éÆÀ¤¿Åý·×Ū¤ÊÉÑÅ٥ơ¼¥Ö¥ë¤Ë´ð¤Å¤¤¤Æ¡¢
³Æ¸¡º÷ʸ»úÎ󤫤éºÇ¤âµ©¤Êʸ»ú¤òÁª¤Ö¡£
¤³¤Î"ºÇ¤âµ©¤Ê"ʸ»ú¤ò´Þ¤à°ÌÃ֤ΤߤòÄ´¤Ù¤ë¤Î¤Ç¤¢¤ë¡£)
Î㤨¤Ð¡¢¼¡¤Î¥ë¡¼¥×¤Ï¡¢¤¢¤ë¥Ñ¥¿¡¼¥ó¤ò´Þ¤à¹Ô¤ÎÁ°¤Ë¡¢
¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò´Þ¤à¥¨¥ó¥È¥ê¤ò½ÐÎϤ¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
while (<>) { study; print ".IX foo\n" if /\bfoo\b/; print ".IX bar\n" if /\bbar\b/; print ".IX blurfl\n" if /\bblurfl\b/; ... print; }
/\bfoo\b/
¤ò¸¡º÷¤¹¤ë»þ¤Ï¡¢
$_
Ãæ¤Î `f' ¤Î°ÌÃ֤ΤߤòÄ´¤Ù¤ë¡£
¤Ê¤¼¤Ê¤é¡¢`f' ¤Ï `o' ¤è¤ê¤âµ©¤À¤«¤é¤Ç¤¢¤ë¡£
°ìÈÌŪ¤Ë¡¢Æüì¤Ê¾ì¹ç¤ò½ü¤¤¤Æ¤³¤ì¤Ï¸ú²Ì¤¬¤¢¤ë¡£
Í£°ì¤ÎÌäÂê¤Ï¡¢¤³¤ì¤Ë¤è¤êºÇ½é¤Ë linked list ¤òºî¤ë¤Î¤Ë¤«¤«¤Ã¤¿°Ê¾å¤Ë
»þ´Ö¤òÀáÌó¤Ç¤¤ë¤«¤É¤¦¤«¤Ç¤¢¤ë¡£
Ãí°Õ:eval
¤¹¤ë¤³¤È¤Ç
²¿²ó¤âÁ´¥Ñ¥¿¡¼¥ó¤ò¥³¥ó¥Ñ¥¤¥ë¤·Ä¾¤¹¤Î¤òËɤ°¤³¤È¤¬¤Ç¤¤ë¡£
¤³¤ì¤È¹ç¤ï¤»¤Æ¡¢Á´¥Õ¥¡¥¤¥ë¤¬ 1 ¥ì¥³¡¼¥É¤Ë¤Ê¤ë¤è¤¦¤Ë $/
¤ò undef ¤¹¤ë¤È¡¢
ÂçÊÑ®¤¯¡¢ÀìÍÑ¤Î¥×¥í¥°¥é¥à fgrep
¤è¤ê¤â®¤¤¤³¤È¤¬Â¿¤¤¡£
°Ê²¼¤ÎÎã¤Ç¤Ï ¥Õ¥¡¥¤¥ë·²(@files
) ¤«¤éñ¸ì·²(@words
) ¤ò¸¡º÷¤·¡¢
¥Þ¥Ã¥Á¤¹¤ë¥Õ¥¡¥¤¥ë¤Î̾Á°¤ò½ÐÎϤ¹¤ë¡£
$search = 'while (<>) { study;'; foreach $word (@words) { $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n"; } $search .= "}"; @ARGV = @files; undef $/; eval $search; # ¤³¤ì¤ÏÂçÊÑ(this screams) $/ = "\n"; # Ä̾ï¤Î delimiter ¤ËÌ᤹ foreach $file (sort keys(%seen)) { print $file, "\n"; }
=~
¤ä !~
¤ò»È¤Ã¤Æʸ»úÎó¤ò»ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢
$_
ʸ»úÎó¤¬ÊÑ´¹¤µ¤ì¤ë¡£
(=~
¤ò»È¤Ã¤Æ»ØÄꤹ¤ëʸ»úÎó¤Ï¥¹¥«¥é¡¼ÊÑ¿ô¡¢ÇÛÎó¤Î 1 Í×ÁÇ¡¢
¤Þ¤¿¤Ï¤³¤ì¤é¤Ø¤ÎÂåÆþ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£Â¨¤Á¡¢º¸ÊÕÃÍ¡£)
sed ¿®¼Ô¤Î¤¿¤á¤Ë¡¢y
¤â tr
¤ÎÊÌ̾¤È¤·¤Æ¤¢¤ë¡£
SEARCHLIST ¤¬³ç¸ÌÎà¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
REPLACEMENTLIST ¤Ë¤Ï¤½¤ìÍѤζèÀÚ¤ê¤Î¥Ú¥¢¤ò»ØÄꤹ¤ë¤¬¡¢
¤½¤ì¤Ï³ç¸ÌÎà¤Ç¤¢¤Ã¤Æ¤â¤Ê¤¯¤Æ¤â¤è¤¤¡£
Îã: tr[A-Z][a-z]
¤ä tr(+-*/)/ABCD/
¡£
c
¤ò»ØÄꤹ¤ë¤È¡¢
SEARCHLIST ʸ»ú¥»¥Ã¥È¤ÎÊ佸¹ç¤¬»È¤ï¤ì¤ë¡£d
¤ò»ØÄꤹ¤ë¤È¡¢SEARCHLIST ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ëʸ»ú¤Ç¡¢tr
¥×¥í¥°¥é¥à¤ÎµóÆ°¤ËÈæ¤Ù¤Æ¤è¤ê½ÀÆð¤Ê½èÍý¤Ç¤¢¤ë¡£
tr
¥×¥í¥°¥é¥à¤Ë¤Ï¡¢
SEARCHLIST ¤Ë´Þ¤Þ¤ì¤ëʸ»ú¤òÁ´¤Æºï½ü¤¹¤ë¤â¤Î¤¬¤¢¤ë)s
¤ò»ØÄꤹ¤ë¤È¡¢
ÊÑ´¹¤µ¤ì¤ÆƱ¤¸Ê¸»ú¤Ë¤Ê¤Ã¤¿Ê¸»úÎó¤ò 1 ʸ»ú¤Ë½Ì¤á¤ë¡£d
¤òÍѤ¤¤ë¤È¡¢
REPLACEMENTLIST ¤Ï¾ï¤Ë»ØÄꤷ¤¿¤½¤Î¤â¤Î¤È¤·¤Æ²ò¼á¤µ¤ì¤ë¡£
¤½¤ì°Ê³°¤Î¾ì¹ç¤Ç¡¢
REPLACEMENTLIST ¤¬ SEARCHLIST ¤è¤ê¤âû¤¤¾ì¹ç¤Ï¡¢
Ʊ¤¸Ä¹¤µ¤Ë¤Ê¤ë¤Þ¤ÇºÇ¸å¤Îʸ»ú¤¬·«¤êÊÖ¤µ¤ì¤ë¡£
REPLACEMENTLIST ¤¬¥Ì¥ë¤Î¾ì¹ç¤Ï¡¢SEACHLIST ¤¬¥³¥Ô¡¼¤µ¤ì¤ë¡£
¤³¤Î¸å¼Ô¤Ï¡¢¤¢¤ë¥¯¥é¥¹¤Ë´Þ¤Þ¤ì¤ëʸ»ú¤ò¥«¥¦¥ó¥È¤·¤¿¤ê¡¢
¤¢¤ë¥¯¥é¥¹¤Îʸ»ú¤ÎϢ³¤ò½Ì¤á¤¿¤ê¤¹¤ë¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£
$ARGV[1] =~ y/A-Z/a-z/; # ¾®Ê¸»ú¤ËÅý°ì¤¹¤ë $cnt = tr/*/*/; # $_ Æâ¤Î * ¤ò¿ô¤¨¤ë $cnt = tr/0-9//; # $_ Æâ¤Î¿ô»ú¤ò¿ô¤¨¤ë tr/a-zA-Z//s; # bookkeeper -> bokeper ($HOST = $host) =~ tr/a-z/A-Z/; y/a-zA-Z/ /cs; # ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È°Ê³°¤ò 1 ʸ»ú¤Î¥¹¥Ú¡¼¥¹¤ËÃÖ´¹ tr/\200-\377/\0-\177/; # 8 ¥Ó¥Ã¥ÈÌܤò¾Ã¤¹
SIGALRM
¤ò¥×¥í¥»¥¹¤ËÅÁ¤¨¤ë¡£
¤Ä¤Þ¤ê¡¢
`alarm(15)' ¤Ï¤½¤ì¤«¤é 14 Éðʾå·Ð¤Ã¤¿¤¢¤ë»þÅÀ¤Ç SIGALRM
¤òµ¯¤³¤¹¡£
Ʊ»þ¤Ë¤Ï°ì¤Ä¤Î¥¿¥¤¥Þ¡¼¤·¤«¥«¥¦¥ó¥È¤Ç¤¤Ê¤¤¡£
¥³¡¼¥ë¤¹¤ëÅÙ¤ËÁ°¤Î¥¿¥¤¥Þ¡¼¤ò»È¤¨¤Ê¤¯¤¹¤ë¤·¡¢
¤Þ¤¿°ú¿ô¤È¤·¤Æ 0 ¤òÍ¿¤¨¤ë¤È
¿·¤·¤¤¥¿¥¤¥Þ¡¼¤ò³«»Ï¤»¤º¤ËÁ°¤Î¥¿¥¤¥Þ¡¼¤ò¥¥ã¥ó¥»¥ë¤¹¤ë¡£
ÊÖ¤êÃͤÏÁ°¤Î¥¿¥¤¥Þ¡¼¤Ë»Ä¤Ã¤Æ¤¤¤¿»þ´Ö¤Ç¤¢¤ë¡£
$_
¤Ë chroot
¤¹¤ë¡£eval
¤Î³°¤Ç¤Ï¡¢LIST ¤ÎÃͤò STDERR ¤Ë½ÐÎϤ·¡¢
¸½ºß¤Î $!
(errno) ¤Ç exit
¤¹¤ë¡£
¤â¤· $!
¤¬ 0 ¤Ê¤é¡¢
($?
>> 8 ) (`command`
¤Î¥¹¥Æ¡¼¥¿¥¹) ¤Ç exit
¤¹¤ë¡£
¤â¤· ($?
>> 8 ) ¤¬ 0 ¤Ê¤é¡¢255 ¤Ç exit
¤¹¤ë¡£
eval
¤ÎÃæ¤Ç¤Ï¡¢¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤¬ $@
¤ËÆþ¤ê¡¢
eval
¤¬ undefined value ¤Ç½ªÎ»¤¹¤ë¡£
die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; chdir '/usr/spool/news' || die "Can't cd to spool: $!\n"EXPR ¤ÎÃͤ¬²þ¹Ô¤Ç½ª¤ï¤é¤Ê¤¤¾ì¹ç¤Ï¡¢ ¥¹¥¯¥ê¥×¥È¤Î¸½ºß¤Î¹ÔÈֹ椪¤è¤Ó(¤â¤·¤¢¤ì¤Ð)ÆþÎϹÔÈÖ¹æ¤âɽ¼¨¤µ¤ì¡¢ ²þ¹Ô¤¬ÉÕ¤±²Ã¤¨¤é¤ì¤ë¡£ ¥Ò¥ó¥È: ¥á¥Ã¥»¡¼¥¸¤Ë `, stopped' ¤òÉÕ¤±²Ã¤¨¤Æ¤ª¤¯¤È¡¢ `at foo line 123' ¤¬ÉÕ¤±²Ã¤¨¤é¤ì¤¿»þ¤Ë¤è¤ê¤ï¤«¤ê¤ä¤¹¤¤¡£
die "/etc/games is no good"; die "/etc/games is no good, stopped";¤Ï¤½¤ì¤¾¤ì¼¡¤Î¤è¤¦¤Ë½ÐÎϤ¹¤ë¡£
/etc/games is no good at canasta line 123. /etc/games is no good, stopped at canasta line 123.See section exit.
execvp()
¤ò¥³¡¼¥ë¤¹¤ë¡£
¥¹¥«¥é¡¼°ú¿ô¤¬ 1 ¤·¤«¤Ê¤¤¾ì¹ç¡¢
°ú¿ô¤Ë¥·¥§¥ë¤Î¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤¬¤¢¤ë¤«¤É¤¦¤«¥Á¥§¥Ã¥¯¤µ¤ì¤ë¡£
¤â¤·¤¢¤ì¤Ð¡¢parse ¤¹¤ë¤¿¤á¤ËÁ´°ú¿ô¤¬ `/bin/sh -c' ¤ËÅϤµ¤ì¤ë¡£
¤â¤·¤Ê¤±¤ì¤Ð¡¢°ú¿ô¤Ïñ¸ìËè¤Ëʬ¤±¤é¤ì¡¢execvp()
¤Ë¤½¤Î¤Þ¤ÞÅϤµ¤ì¤ë¡£
¤³¤ÎÊý¤¬¸úΨŪ¤À¤«¤é¤Ç¤¢¤ë¡£
Ãí°Õ:exec
(¤ª¤è¤Ó system
)¤Ï½ÐÎϥХåե¡¤ò¥Õ¥é¥Ã¥·¥å¤·¤Ê¤¤¤Î¤Ç¡¢
½ÐÎϤò¼º¤ï¤Ê¤¤¤¿¤á¤Ë $|
¤ò¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
exec '/bin/echo', 'Your arguments are: ', @ARGV; exec "sort $outfile | uniq";ËÜÅö¤ÏÂè°ì°ú¿ô¤ò¼Â¹Ô¤·¤¿¤¯¤Ê¤¤¤¬¡¢ ¥×¥í¥°¥é¥à¤ò¤À¤Þ¤·¤Æ¤½¤Î̾Á°¤Ç¼Â¹Ô¤·¤Æ¤¤¤ë¤è¤¦¤Ë¸«¤»¤¿¤¤»þ¤Ï¡¢ ËÜÅö¤ËÁö¤é¤»¤¿¤¤¥×¥í¥°¥é¥à̾¤òÊÑ¿ô¤ËÂåÆþ¤·¡¢ ¤½¤ÎÊÑ¿ô¤ò LIST ¤ÎÁ°¤Ë¥³¥ó¥Þ¤È¶¦¤Ë»ØÄꤹ¤ì¤ÐÎɤ¤ (¤³¤¦¤¹¤ë¤È LIST ¤Ë¥¹¥«¥é¡¼¤¬°ì¤Ä¤·¤«¤Ê¤¯¤Æ¤â¡¢ LIST ¤¬¾ï¤ËÊ£¿ô¤ÎÃͤò»ý¤Ã¤Æ¤¤¤ë¤È²ò¼á¤µ¤ì¤ë)¡£
$shell = '/bin/csh'; exec $shell '-sh'; # ¥í¥°¥¤¥ó¥·¥§¥ë¤Î¤Õ¤ê¤ò¤¹¤ë
exit
¤¹¤ë¡£
$ans = <STDIN>; exit 0 if $ans =~ /^[Xx]/;EXPR ¤ò¾Êά¤¹¤ë¤È¡¢status 0 ¤Ç
exit
¤¹¤ë¡£
See section die.
fork()
¥³¡¼¥ë¤ò¹Ô¤¦¡£¿Æ¥×¥í¥»¥¹¤Ë¤Ï»Ò¶¡¤Î¥×¥í¥»¥¹ ID ¤òÊÖ¤·¡¢
»Ò¥×¥í¥»¥¹¤Ë¤Ï 0 ¤òÊÖ¤¹¡£
Ãí°Õ:$|
¤ò¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$|@hfil} : write ¤Þ¤¿¤Ï print ¤Î¸å¤Ë¥Õ¥é¥Ã¥·¥å¤ò¹Ô¤¦¤«Èݤ«}.
getpwuid
¤ò»È¤¦¤³¤È¡£
$login = getlogin || (getpwuid($<))[0] || "Somebody";
getpwuid
¤Ë¤Ä¤¤¤Æ¤Ï
See section ¥·¥¹¥Æ¥à¥Õ¥¡¥¤¥ë¤«¤é¥Ç¡¼¥¿¤òÆÀ¤ë´Ø¿ô.getpgrp(2)
¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥Þ¥·¥ó¤Ç»ÈÍѤ¹¤ë¤È
Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢¸½¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹¥°¥ë¡¼¥×¤òÊÖ¤¹¡£getpriority(2)
¤ò»²¾È¤Î¤³¤È¡£)
getpriority(2)
¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥Þ¥·¥ó¤Ç»ÈÍѤ¹¤ë¤È
Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£$cnt = kill 1, $child1, $child2; kill 9, @goners;¥·¥°¥Ê¥ë¤¬Éé¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ç¤Ï¤Ê¤¯¥×¥í¥»¥¹¥°¥ë¡¼¥×¤ò
kill
¤¹¤ë¡£
(System V ¤Ç¤Ï¡¢
Éé¤Î¥×¥í¥»¥¹ÈÖ¹æ¤Ï¥×¥í¥»¥¹¥°¥ë¡¼¥×¤â kill
¤¹¤ë¤¬¡¢¸ß´¹À¤Ï¤Ê¤¤¡£)
¥·¥°¥Ê¥ë̾¤ò»ØÄꤷ¤Æ¤â¤è¤¤¡£setpgrp(2)
¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥Þ¥·¥ó¤Ç¤ÏÃ×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£setpriority(2)
¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¥Þ¥·¥ó¤Ç¤Ï
Ã×̿Ū¥¨¥é¡¼¤È¤Ê¤ë¡£
(setpriority(2)
¤ò»²¾È¡£)
SIGALRM
¤òÁ÷¤ë¤È interrupt ¤Ç¤¤ë¤À¤í¤¦¡£
¼ÂºÝ¤ËÄä»ß¤·¤¿»þ´Ö¤òÊÖ¤¹¡£
¤ª¤½¤é¤¯ alarm
¤È sleep
¤òº®ºß¤µ¤»¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¤À¤í¤¦¡£
sleep() ¤Ï alarm() ¤òÍѤ¤¤Æ¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤¬
¿¤¤¤«¤é¤À¡£require 'syscall.ph'; # h2ph ¤ÎɬÍפ¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤ syscall(&SYS_write, fileno(STDOUT), "hi there\n", 9);
fork
¤ò¹Ô¤¤¡¢
¿Æ¥×¥í¥»¥¹¤Ï»Ò¥×¥í¥»¥¹¤¬´°Î»¤¹¤ë¤Î¤òÂÔ¤ÄÅÀ¤Ç¤¢¤ë¡£
Ãí°Õ: °ú¿ô¤Î½èÍý¤Ï°ú¿ô¤Î¿ô¤Ë¤è¤Ã¤ÆÊѤï¤ë¡£
ÊÖ¤êÃÍ¤Ï¥×¥í¥°¥é¥à¤Î exit status ¤Ç¡¢wait()
¤ÈƱ¤¸¤Ç¤¢¤ë¡£($user,$system,$cuser,$csystem) = times;
$?
¤ËÊ֤롣See section waitpid.$?
¤ËÊ֤롣¼¡¤Î¤è¤¦¤Ê¥³¡¼¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¢
require "sys/wait.h"; ... waitpid(-1,&WNOHANG);¤É¤ó¤Ê¥×¥í¥»¥¹¤ËÂФ·¤Æ¤â non-blocking wait ¤ò¼Â¹Ô¤Ç¤¤ë¡£ non-blocking wait ¤Ï waitpid(2) ¤Þ¤¿¤Ï wait4(2) ¤Î ¤É¤Á¤é¤«¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥Þ¥·¥ó¤Ç¤Î¤ß¼Â¹Ô²Äǽ¤Ç¤¢¤ë¡£ ¤·¤«¤·¡¢FLAGS ¤ò 0 ¤Ë¤·¤Æ¡¢¤¢¤ë pid ¤ò wait ¤¹¤ë¤Î¤Ï ¤É¤³¤Ç¤Ç¤â¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤Æ¤¤¤ë¡£(perl ¤Ï¡¢ exit ¤·¤¿¤¬¤Þ¤À perl ¥¹¥¯¥ê¥×¥È¤¬¼è¤êÆþ¤ì(harvest)¤·¤Æ¤¤¤Ê¤¤¥×¥í¥»¥¹¤Î ¥¹¥Æ¡¼¥¿¥¹Ãͤò³Ð¤¨¤Æ¤ª¤¯¤³¤È¤Ç¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¥¨¥ß¥å¥ì¡¼¥È¤ò¤¹¤ë¡£)
STDERR
¤Ë½Ð¤¹¤¬¡¢exit
¤·¤Ê¤¤¡£
# ¥¤¥ó¥¿¡¼¥Í¥Ã¥È¥½¥±¥Ã¥È¥¢¥É¥ì¥¹ $sockaddr = 'S n a4 x8'; $hersockaddr = getpeername(S); ($family, $port, $heraddr) = unpack($sockaddr,$hersockaddr);
# ¥¤¥ó¥¿¡¼¥Í¥Ã¥È¥½¥±¥Ã¥È¥¢¥É¥ì¥¹ $sockaddr = 'S n a4 x8'; $mysockaddr = getsockname(S); ($family, $port, $myaddr) = unpack($sockaddr,$mysockaddr);
listen
¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÈƱ¤¸¤³¤È¤ò¤¹¤ë¡£
À®¸ù¤¹¤ì¤Ð¿¿¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ðµ¶¤òÊÖ¤¹¡£¥×¥í¥»¥¹´ÖÄÌ¿®¤Î¾Ï¤ÎÎã¤ò»²¾È¡£
See section ¥×¥í¥»¥¹´ÖÄÌ¿®.&IPC_STAT
¤Ç¤¢¤ë¾ì¹ç¤Ï¡¢
ARG ¤ÏÊÑ¿ô¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢¤³¤ì¤Ë msqid_ds ¹½Â¤ÂΤ¬Ê֤äƤ¯¤ë¡£
ioctl
¤ÈƱÍͤÎÃͤòÊÖ¤¹¡£
¤¹¤Ê¤ï¤Á¡¢¥¨¥é¡¼¤¬¤¢¤ì¤Ð undefined ¤ÎÃÍ¡¢¥¼¥í¤Î¾ì¹ç¤Ï `0 ¤À¤¬¿¿'¡¢
¤½¤Î¾¤Î¾ì¹ç¤Ï¼ÂºÝ¤ÎÊÖ¤êÃͤ¬Ê֤롣&IPC_STAT
¤Þ¤¿¤Ï &GETALL
¤Ê¤é¡¢
ARG ¤ÏÊÑ¿ô¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
¤³¤ì¤Ë semid_ds ¹½Â¤ÂΤޤ¿¤Ï¥»¥Þ¥Õ¥©ÃͤÎÇÛÎó¤¬Ê֤롣
ioctl
¤ÈƱÍͤÎÃͤòÊÖ¤¹¡£
¤¹¤Ê¤ï¤Á¡¢¥¨¥é¡¼¤¬¤¢¤ì¤Ð undefined ¤ÎÃÍ¡¢¥¼¥í¤Î¾ì¹ç¤Ï `0 ¤À¤¬¿¿'¡¢
¤½¤Î¾¤Î¾ì¹ç¤Ï¼ÂºÝ¤ÎÊÖ¤êÃͤ¬Ê֤롣pack
¤·¤¿¤â¤Î¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
semop ¹½Â¤ÂΤϡ¢
`pack("sss", $semnum, $semop, $semflag)'¤Çºî¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¥»¥Þ¥Õ¥©½èÍý¤Î¿ô¤Ï OPSTRING ¤ÎŤµ¤Ç°ÅÌÛ¤ÎÆâ¤Ë»ØÄꤵ¤ì¤ë¡£
À®¸ù¤¹¤ì¤Ð¿¿¡¢¥¨¥é¡¼¤¬¤¢¤ì¤Ðµ¶¤òÊÖ¤¹¡£$semid
¤Î¥»¥Þ¥Õ¥© $semnum
¤òÂԤġ£
$semop = pack("sss", $semnum, -1, 0); die "Semaphore trouble: $!\n" unless semop($semid, $semop);¥»¥Þ¥Õ¥©¤Ë¥·¥°¥Ê¥ë¤òÁ÷¤ë¤Ë¤Ï¡¢`-1' ¤ò `1' ¤ËÃÖ¤´¹¤¨¤ì¤Ð¤è¤¤¡£
&IPC_STAT
¤Ç¤¢¤ë¾ì¹ç¤Ï¡¢
ARG ¤ÏÊÑ¿ô¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
¤³¤ì¤Ë shmid_ds ¹½Â¤ÂΤ¬Ê֤äƤ¯¤ë¡£
ioctl
¤ÈƱÍͤÎÃͤòÊÖ¤¹¡£
¤¹¤Ê¤ï¤Á¡¢¥¨¥é¡¼¤¬¤¢¤ì¤Ð undefined ¤ÎÃÍ¡¢¥¼¥í¤Î¾ì¹ç¤Ï `0 ¤À¤¬¿¿'¡¢
¤½¤Î¾¤Î¾ì¹ç¤Ï¼ÂºÝ¤ÎÊÖ¤êÃͤ¬Ê֤롣°Ê²¼¤Î * ¤ÎÉôʬ¤Ë¤Ï¡¢³Æ¥·¥¹¥Æ¥à¥Õ¥¡¥¤¥ë¤ËÂбþ¤·¤Æ¡¢
/etc/passwd ¢ª pw /etc/group ¢ª gr /etc/hosts ¢ª host /etc/networks ¢ª net /etc/protocols ¢ª proto /etc/services ¢ª serv
¤¬¤½¤ì¤¾¤ìÆþ¤ë¡£
getpwnam(NAME)
, getgrnam(NAME)
,
gethostbyname(NAME)
, getnetbyname(NAME)
,getprotobyname(NAME)
, getservbyname(NAME,PROTO)
getpwuid(UID)
, getgrgid(GID)
gethostbyaddr(ADDR,ADDRTYPE)
, getnetbyaddr(ADDR,ADDRTYPE)
, getprotobynumber(NUMBER)
, getservbyport(PORT,PROTO)
getpwent
, getgrent
, gethostent
, getnetent
,
getprotoent
, getservent
setpwent
, setgrent
, sethostent(STAYOPEN)
,
setnetent(STAYOPEN)
,setprotoent(STAYOPEN)
,setservent(STAYOPEN)
endpwent
, endgrent
, endhostent
, endnetent
,
endprotoent
, endservent
¤³¤ì¤é¤Î¥ë¡¼¥Á¥ó¤Ï¥·¥¹¥Æ¥à¥é¥¤¥Ö¥é¥êÆâ¤ÎƱÍͤδؿô¤ÈƱ¤¸Æ°ºî¤ò¤¹¤ë¡£
ÇÛÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ë¤ª¤¤¤Æ get
¥ë¡¼¥Á¥ó¤¬ÊÖ¤¹Ãͤϰʲ¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell) = getpw... ($name,$passwd,$gid,$members) = getgr... ($name,$aliases,$addrtype,$length,@addrs) = gethost... ($name,$aliases,$addrtype,$net) = getnet... ($name,$aliases,$proto) = getproto... ($name,$aliases,$port,$proto) = getserv...
(¥¨¥ó¥È¥ê¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð¥Ì¥ë¥ê¥¹¥È¤¬Ê֤롣)
¥¹¥«¥é¡¼¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢Ì¾Á°(name) ¤¬Ê֤롣 ̾Á°¤Ç¤Î»²¾È¤Î¾ì¹ç¤Ï¡¢¤½¤ì°Ê³°¤Î³Æ¼ï¤ÎÃͤ¬Ê֤롣 (¥¨¥ó¥È¥ê¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð undefined ¤¬Ê֤롣)Î㤨¤Ð:
$uid = getpwnam $name = getpwuid $name = getpwent $gid = getgrnam $name = getgrgid $name = getgrent ¤Ê¤É¡£
getgr
... ¤¬ÊÖ¤¹ÃÍ $members
¤Ï
¥°¥ë¡¼¥×¤Î¥á¥ó¥Ð¡¼¤Î¥í¥°¥¤¥ó̾¤Î¥ê¥¹¥È¤ò¥¹¥Ú¡¼¥¹¤Ç¶èÀڤ俤â¤Î¤Ç¤¢¤ë¡£
gethost
... ´Ø¿ô¤Ë¤Ä¤¤¤Æ¤Ï¡¢
C ¤¬ h_errno
¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
¥³¡¼¥ë¤¬¼ºÇÔ¤¹¤ì¤Ð¤½¤ÎÃͤ¬ $?
¤ËÊ֤롣
¥³¡¼¥ë¤¬À®¸ù¤·¤¿¾ì¹ç¡¢ÊÖ¤ëÃÍ @addrs
¤Ï
Âбþ¤¹¤ë¥·¥¹¥Æ¥à¥é¥¤¥Ö¥é¥ê¤ò¥³¡¼¥ë¤·¤ÆÆÀ¤é¤ì¤ë raw address ¤Î¥ê¥¹¥È¤Ç¤¢¤ë¡£
Internet ¤Î domain ¤Ç¤Ï¡¢³Æ¥¢¥É¥ì¥¹¤ÏŤµ 4 ¥Ð¥¤¥È¤Ç¡¢
¼¡¤Î¤è¤¦¤Ë¤·¤Æ unpack
¤Ç¤¤ë¡£
($a,$b,$c,$d) = unpack('C4',$addr[0]);
($package,$filename,$line) = caller;EXPR ¤ò»ØÄꤹ¤ë¤È¡¢ ¥Ç¥Ð¥Ã¥¬¤¬¥¹¥¿¥Ã¥¯¥È¥ì¡¼¥¹¤ò½ÐÎϤ¹¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ë¾ðÊó¤âÊÖ¤¹¡£ EXPR ¤ÎÃͤ¬¡¢ ¸½ºß¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÁ°¤Ë call ¥Õ¥ì¡¼¥à¤¬¤¤¤¯¤Ä¤¢¤ë¤«¤ò¼¨¤¹¡£
print if defined $switch{'D'}; print "$val\n" while defined($val = pop(@ary)); die "Can't readlink $sym: $!" unless defined($value = readlink $sym); eval '@foo = ()' if defined(@foo); die "No XYZ package defined" unless defined %_XYZ; sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }See section undef.
goto
¤¬¤â¤ÄÀ©¸Â¤ÏÁ´¤ÆŬÍѤµ¤ì¤ë)¡£
dump
¤Ï ¥³¥¢¥À¥ó¥×¤ò¤Ï¤µ¤ó¤À goto
+ ºÆ¥¹¥¿¡¼¥È ¤È¹Í¤¨¤ì¤Ð¤è¤¤¡£
LABEL ¤ò¾Êά¤¹¤ë¤È¡¢¥×¥í¥°¥é¥à¤ÎÀèƬ¤«¤éºÆ¥¹¥¿¡¼¥È¤¹¤ë¡£
·Ù¹ð: dump
¤Î»þÅÀ¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤¿¥Õ¥¡¥¤¥ë¤Ï¤¹¤Ù¤Æ
¥×¥í¥°¥é¥à¤¬ºÆÀ¸¤·¤¿»þ¤Ë¤Ï¥ª¡¼¥×¥ó¤µ¤ì¤Ê¤¤
(perl ¤Î¦¤«¤é¤ß¤ë¤Èº®Í𤹤뤿¤á)¡£
-u
¥ª¥×¥·¥ç¥ó¤â»²¾È¤Î¤³¤È¡£
See section ¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó.
#!/usr/bin/perl require 'getopt.pl'; require 'stat.pl'; %days = ( 'Sun',1, 'Mon',2, 'Tue',3, 'Wed',4, 'Thu',5, 'Fri',6, 'Sat',7); dump QUICKSTART if $ARGV[0] eq '-d'; QUICKSTART: do Getopt('f');
eval
¡¦do
¤Ë¥í¡¼¥«¥ë¤Ç¤¢¤ë¤ÈÀë¸À¤¹¤ë¡£¥ê¥¹¥ÈÃæ¤ÎÁ´Í×ÁǤϺ¸ÊÕÃͤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
local
¤Ï LIST Ãæ¤ÎÊÑ¿ô¤ÎÃͤò¥¹¥¿¥Ã¥¯¤ËÊݸ¤·¡¢
¥Ö¥í¥Ã¥¯¡¦¥µ¥Ö¥ë¡¼¥Á¥ó¡¦eval
¤«¤éÈ´¤±¤ë»þ¤Ë¸µ¤ËÌ᤹¡£
¤³¤Î¤¿¤á¡¢¸Æ¤Ð¤ì¤¿¥µ¥Ö¥ë¡¼¥Á¥ó¤Ç¤Ï¥í¡¼¥«¥ëÊÑ¿ô¤Ï»²¾È¤Ç¤¤ë¤¬¡¢
¥°¥í¡¼¥Ð¥ë¤ÊÊÑ¿ô¤Ï»²¾È¤Ç¤¤Ê¤¤¤³¤È¤Ë¤Ê¤ë¡£
LIST ¤Ï´õ˾¤Ë¤è¤êÃͤòÂåÆþ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¤³¤ì¤Ë¤è¤ê¥í¡¼¥«¥ëÊÑ¿ô¤ò½é´ü²½¤Ç¤¤ë¡£
(¤¢¤ëÊÑ¿ô¤Ë¤Ä¤¤¤Æ½é´ü²½¤ò»Ø¼¨¤·¤Ê¤¤¾ì¹ç¡¢ÃÍ¤Ï undefined ¤ÇºîÀ®¤µ¤ì¤ë¡£)
Ä̾¥µ¥Ö¥ë¡¼¥Á¥ó¤Ø¤Î¥Ñ¥é¥á¡¼¥¿¤Ë̾Á°¤òÉÕ¤±¤ë¤Î¤ËÍѤ¤¤ë¡£
sub RANGEVAL { local($min, $max, $thunk) = @_; local($result) = "; local($i); # $thunk ¤Ï $i ¤ò»²¾È¤¹¤ë¤È²¾Äꤷ¤Æ¤¤¤ë for ($i = $min; $i < $max; $i++) { $result .= eval $thunk; } $result; } if ($sw eq '-v') { # ¥°¥í¡¼¥Ð¥ë¤ÊÇÛÎó¤Ç¥í¡¼¥«¥ë¤ÊÇÛÎó¤ò½é´ü²½ local(@ARGV) = @ARGV; unshift(@ARGV,'echo'); system @ARGV; } # @ARGV ¤ÏÊݸ¤µ¤ì¤ë # Ï¢ÁÛÇÛÎó¤Ë°ì»þŪ¤Ë¿ô»ú¤òÉղ乤ë if ($base12) { # (Ãí°Õ: ¤³¤ì¤¬¸úΨ¤¬¤è¤¤¤ï¤±¤Ç¤Ï¤Ê¤¤!) local(%digits) = (%digits,'t',10,'e',11); do parse_num(); }Ãí°Õ:
local()
¤Ï run-time ¥³¥Þ¥ó¥É¤Ç¤¢¤ê¡¢¥ë¡¼¥×¤Ç¤ÏËè²ó¼Â¹Ô¤µ¤ì¤ë¡£
¤³¤Î¤¿¤á¥ë¡¼¥×¤«¤éÈ´¤±¤Æ²òÊü¤¹¤ë¤Þ¤Ç¡¢Ëè²ó¥¹¥¿¥Ã¥¯¤ò¾ÃÈñ¤¹¤ë¡£q
¤Ï°ìÈ̲½¤µ¤ì¤¿¥·¥ó¥°¥ë¥¯¥©¡¼¥È¤Ç¤¢¤ê¡¢
qq
¤Ï°ìÈ̲½¤µ¤ì¤¿¥À¥Ö¥ë¥¯¥©¡¼¥È¤Ç¤¢¤ë¡£
qx
¤Ï°ìÈ̲½¤µ¤ì¤¿¥Ð¥Ã¥¯¥¯¥©¡¼¥È¤Ç¤¢¤ë¡£
/
¤ÎÂå¤ï¤ê¤Ë
²þ¹Ô¤ò´Þ¤à¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¡¦¿ô»ú¤Ç¤Ê¤¤Ç¤°Õ¤Îʸ»ú¤ò delimiter ¤È¤·¤Æ»È¤¨¤ë¡£
delimiter ¤¬ (
¤Þ¤¿¤Ï {
¤Î¾ì¹ç¤Ï¡¢
ºÇ¸å¤Î delimiter ¤ÏÂбþ¤¹¤ë )
¡¢}
¤È¤Ê¤ë¡£
( )
¤ä }
¤¬Ê¸»úÎó¤ËËä¤á¹þ¤Þ¤ì¤ë¾ì¹ç¤Ï
½¾ÍèÄ̤ê¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤ò¤Ä¤±¤ëɬÍפ¬¤¢¤ë¡£)
$foo = q!I said, "You said, 'She said it.'"!; $bar = q('This is it.'); $today = qx{ date }; $_ .= qq *** The previous line contains the naughty word "$&".\n if /(ibm|apple|awk)/; # :-)
$_
¤Ç¼¨¤µ¤ì¤ë
¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¡£
¼¡¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤ÈƱ¤¸°ÕÌ£¤¬¤¢¤ë¡£
sub require { local($filename) = @_; return 1 if $INC{$filename}; local($realfilename,$result); ITER: { foreach $prefix (@INC) { $realfilename = "$prefix/$filename"; if (-f $realfilename) { $result = do $realfilename; last ITER; } } die "Can't find $filename in \@INC"; } die $@ if $@; die "$filename did not return true value" unless $result; $INC{$filename} = $realfilename; $result; }Ãí°Õ: Ʊ¤¸Ì¾Á°¤Ç¥Õ¥¡¥¤¥ë¤òÆóÅÙ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£½é´ü²½¥³¡¼¥É¤Î ¼Â¹Ô¤¬À®¸ù¤·¤¿¤³¤È¤ò¼¨¤¹¤¿¤á¡¢¥Õ¥¡¥¤¥ë¤ÏºÇ¸å¤Îʸ¤Ç true ¤òÊÖ¤µ¤Ê¤±¤ì¤Ð¤Ê ¤é¤Ê¤¤¡£¤½¤Î¤¿¤á¡¢¤³¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤Ï
1;
¤Ç½ª¤ï¤ë¤Î¤¬½¬´·¤Ç¤¢¤ë
(¤½¤ì¤ò¤·¤Ê¤¯¤Æ¤â true ¤òÊÖ¤¹¤³¤È¤¬¤Ï¤Ã¤¤ê¤·¤Æ¤¤¤Ê¤¤¤«¤®¤ê)¡£
See section {@tt@INC} : perl ¥¹¥¯¥ê¥×¥È¤òõ¤¹¾ì½ê¤Î¥ê¥¹¥È.
continue
¥Ö¥í¥Ã¥¯¤ÎÃæ¤Ç¡¢
ÊÑ¿ô¤ò clear ¤·¡¢??
¸¡º÷¤ò¥ê¥»¥Ã¥È¤·¤Æ
ºÆ¤Ó»ÈÍѲÄǽ¤Ë¤¹¤ë¤¿¤á¤ËÍѤ¤¤ë¡£
EXPR ¤Ïʸ»ú¤Î¥ê¥¹¥È¤È¤·¤Æ²ò¼á¤µ¤ì¤ë(¥Ï¥¤¥Õ¥ó¤ÏÈϰϤò¼¨¤¹)¡£
¤³¤Îʸ»ú¤Î¤É¤ì¤«¤Ç»Ï¤Þ¤ëÊÑ¿ô¤ª¤è¤ÓÇÛÎó¤ÏÁ´¤Æ¸µ¤Î¾õÂ֤˥ꥻ¥Ã¥È¤µ¤ì¤ë¡£
EXPR ¤ò¾Êά¤¹¤ë¤È¡¢
one-match search (?pattern?
)¤¬ match ¤ËºÆ¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
¥«¥ì¥ó¥È¤Î¥Ñ¥Ã¥±¡¼¥¸Æâ¤ÎÊÑ¿ô¡¦¸¡º÷¤Î¤ß¤ò¥ê¥»¥Ã¥È¤¹¤ë¡£
¾ï¤Ë 1 ¤òÊÖ¤¹¡£See section ?¥Ñ¥¿¡¼¥ó?.
reset 'X'; # reset all X variables reset 'a-z'; # reset lower case variables reset; # just reset ?? searchesÃí°Õ:
ARGV
¤ä ENV
¤ÎÆâÍƤò¾Ã¤¹¤«¤é¤Ç¤¢¤ë¡£
dbm Ï¢ÁÛÇÛÎó¤ò¥ê¥»¥Ã¥È¤·¤Æ¤â dbm ¥Õ¥¡¥¤¥ë¤òÊѹ¹¤·¤Ê¤¤¡£
(¤¬¡¢perl ¤¬¥¥ã¥Ã¥·¥å¤·¤¿Á´¥¨¥ó¥È¥ê¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ì¤Ð¡¢Êѹ¹¤¹¤ë¡£
¤³¤¦¤¹¤ì¤Ð¡¢dbm ¥Õ¥¡¥¤¥ë¤ò¶¦Í¤·¤Æ¤¤¤ë»þ¤ËÊØÍø¤Ç¤¢¤ë¡£
ÊØÍø¤Ç¤Ê¤¤¤«¤âÃΤì¤Ê¤¤¤¬¡£)undef
¤¹¤ë¡£
¥¹¥«¥é¡¼ÃÍ¡¢ÇÛÎó¡¢¥µ¥Ö¥ë¡¼¥Á¥ó̾(&
¤òÍѤ¤¤ë)
¤ËÂФ·¤Æ¤Î¤ßÍѤ¤¤ë¤³¤È¡£
(undef
¤Ï¤ª¤½¤é¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ëÊÑ¿ô¤ä dbm ÇÛÎóÃͤο¤¯¤Ë¤Ä¤¤¤Æ
´üÂÔ¤¹¤ëÆ°ºî¤ò¤·¤Ê¤¤¤Ç¤¢¤í¤¦¡£)
¾ï¤Ë undefined value ¤òÊÖ¤¹¡£
EXPR ¤ò¾Êά¤·¤Æ¤âÎɤ¤¤¬¡¢¤³¤Î¾ì¹ç²¿¤â undefine ¤µ¤ì¤º¡¢
Î㤨¤Ð¥µ¥Ö¥ë¡¼¥Á¥ó¤«¤éÊÖ¤ë»þ¤Ë undefined value ¤òÆÀ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
undef $foo; undef $bar{'blurfl'}; undef @ary; undef %assoc; undef &mysub; return (wantarray ? () : undef) if $they_blew_it;
return wantarray ? () : undef;
perl ¤Î±é»»»Ò¤Î·ë¹çµ¬Â§¤ÈÍ¥ÀèÅ٤ϼ¡¤ÎÄ̤ê¤Ç¤¢¤ë¡£
Í¥ÀèÅÙ ·ë¹çµ¬Â§ ±é»»»Ò Ä㤤 ¤Ê¤· print printf exec system sort reverse chmod chown kill unlink utime die return º¸¤«¤é±¦ , ±¦¤«¤éº¸ = += -= *= ¤Ê¤É ±¦¤«¤éº¸ ?: ¤Ê¤· .. º¸¤«¤é±¦ || º¸¤«¤é±¦ && º¸¤«¤é±¦ | ^ º¸¤«¤é±¦ & ¤Ê¤· == != <=> eq ne cmp ¤Ê¤· < > <= >= lt gt le ge ¤Ê¤· chdir exit eval reset sleep rand umask ¤Ê¤· -r -w -x ¤Ê¤É º¸¤«¤é±¦ << >> º¸¤«¤é±¦ + - . º¸¤«¤é±¦ * / % x º¸¤«¤é±¦ =~ !~ ±¦¤«¤éº¸ ! ~ ¤ª¤è¤Óñ¹à±é»»»Ò - ±¦¤«¤éº¸ ** ¤Ê¤· ++ -- ¹â¤¤ º¸¤«¤é±¦ '('
¥ê¥¹¥È¤ò°ú¿ô¤Ë¤È¤ë±é»»»Ò(print
¤½¤Î¾)¤ä
ñ¹à±é»»»Ò¤¹¤Ù¤Æ(chdir
¤Ê¤É)¤Îľ¤°¸å¤í(Ʊ¤¸¹Ô)¤Ëº¸³ç¸Ì¤¬¤¢¤ë¾ì¹ç¡¢
Ä̾ï¤Î´Ø¿ô¸Æ¤Ó½Ð¤·¤ÈƱ¤¸¤è¤¦¤Ë±é»»»Ò¤È³ç¸Ì¤ÎÃæ¤Î°ú¿ô¤ÏºÇ¤â¹â¤¤Í¥ÀèÅÙ¤ò»ý¤Ä¡£
(Îã)
chdir $foo || die; # (chdir $foo) || die chdir($foo) || die; # (chdir $foo) || die chdir ($foo) || die; # (chdir $foo) || die chdir +($foo) || die; # (chdir $foo) || die
¤·¤«¤·¡¢*
¤Ï ||
¤è¤ê¤âÍ¥ÀèÅÙ¤¬¹â¤¤¤Î¤Ç¡¢
chdir $foo * 20; # chdir ($foo * 20) chdir($foo) * 20; # (chdir $foo) * 20 chdir ($foo) * 20; # (chdir $foo) * 20 chdir +($foo) * 20; # chdir ($foo * 20) rand 10 * 20; # rand (10 * 20) rand(10) * 20; # (rand 10) * 20 rand (10) * 20; # (rand 10) * 20 rand +(10) * 20; # rand (10 * 20)
³ç¸Ì¤¬¤Ê¤¤¾ì¹ç¡¢print
, sort
, chmod
¤È¤¤¤Ã¤¿
¥ê¥¹¥È¤ò°ú¿ô¤Ë»ý¤Ä±é»»»Ò¤ÎÍ¥ÀèÅÙ¤Ï
±é»»»Ò¤Îº¸Â¦¤ò¸«¤ë¤«±¦Â¦¤ò¸«¤ë¤«¤Ë¤è¤Ã¤ÆÈó¾ï¤Ë¹â¤¤¤«¡¢
Èó¾ï¤ËÄ㤤¤«¤Î¤É¤Á¤é¤«¤Ç¤¢¤ë¡£
¤¿¤È¤¨¤Ð¡¢¼¡¤ÎÎã¤Ç¡¢
@ary = (1, 3, sort 4, 2); print @ary; # prints 1324
sort
¤Î±¦Â¦¤Ë¤¢¤ë¥³¥ó¥Þ¤Ï sort
¤ÎÁ°¤Ëɾ²Á¤µ¤ì¤ë¤¬¡¢
º¸Â¦¤Î¥³¥ó¥Þ¤Ï sort
¤Î¸å¤Çɾ²Á¤µ¤ì¤ë¡£
¸À¤¤´¹¤¨¤ë¤È¡¢¥ê¥¹¥È¤ò°ú¿ô¤Ë¼è¤ë±é»»»Ò¤Ï
¤½¤ì¤Ë³¤¯°ú¿ô¤ò¤¹¤Ù¤Æ¼«Ê¬¤Î¤â¤Î¤Ë¤·¤Æ¤·¤Þ¤¤¡¢
¤½¤Î¸å¤ÏÁ°¤Ë¤¢¤ë expression ¤Ëñ½ã¤Ë½¾¤¦·¹¸þ¤¬¤¢¤ë¡£
³ç¸Ì¤Ë¤ÏÃí°Õ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
# ¤³¤ì¤é¤Ï print ¤òɾ²Á¤¹¤ëÁ°¤Ë exit ¤òɾ²Á¤·¤Æ¤·¤Þ¤¦ print($foo, exit); # ÌÀ¤é¤«¤Ë¤³¤ì¤ÏÀµ¤·¤¯¤Ê¤¤ print $foo, exit; # ¤³¤ì¤Ç¤â¤Ê¤¤ # ¤³¤ì¤é¤Ï exit ¤òɾ²Á¤¹¤ëÁ°¤Ë print ¤ò¼Â¹Ô¤¹¤ë (print $foo), exit; # ¤³¤ì¤¬Àµ¤·¤¤ print($foo), exit; # ¤Þ¤¿¤Ï¤³¤ì¡£ print ($foo), exit; # ¤³¤ì¤Ç¤âÀµ¤·¤¤¡£
¤Þ¤¿¡¢
print ($foo & 255) + 1, "\n";
¤Ï¤ª¤½¤é¤¯¸«¤¿ÌܤÎÆ°ºî¤Ï¤·¤Ê¤¤¡£
¥µ¥Ö¥ë¡¼¥Á¥ó¤Ï¼¡¤Î¤è¤¦¤ËÀë¸À¤¹¤ë¡£
sub NAME BLOCK
ÅϤ·¤¿°ú¿ô¤ÏÁ´¤ÆÇÛÎó @_
¡¢
¤¹¤Ê¤ï¤Á $_[0]
, $_[1]
,... ¤ËÆþ¤ë¡£
ÇÛÎó @_
¤Ï¥í¡¼¥«¥ë¤ÊÇÛÎó¤À¤¬¡¢
¤½¤ÎÃͤϼºݤΥ¹¥«¥é¡¼¥Ñ¥é¥á¡¼¥¿¤Ø¤Î»²¾È¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÊÖ¤êÃͤϺǸå¤Ëɾ²Á¤·¤¿ expression ¤ÎÃͤǤ¢¤ê¡¢
ÇÛÎóÃͤǤ⥹¥«¥é¡¼ÃͤǤâ¤è¤¤¡£
¤Þ¤¿¡¢ÃͤòÊÖ¤·¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó¤«¤éÈ´¤±¤ë¤³¤È¤ò»Ø¼¨¤¹¤ë¤¿¤á¤Ë¡¢
return
Àë¸À¤ò»È¤Ã¤Æ¤â¤è¤¤¡£
¥í¡¼¥«¥ëÊÑ¿ô¤òºî¤ëÊýË¡¤Ï¡¢local
±é»»»Ò¤Î¹à¤ò»²¾È¤Î¤³¤È¡£
See section local.
¥µ¥Ö¥ë¡¼¥Á¥ó¤Ï do
±é»»»Ò¤Þ¤¿¤Ï &
±é»»»Ò¤òÍѤ¤¤Æ¥³¡¼¥ë¤¹¤ë¡£
Îã:
sub MAX { local($max) = pop(@_); foreach $foo (@_) { $max = $foo if $max < $foo; } $max; } ... $bestday = &MAX($mon,$tue,$wed,$thu,$fri);
Îã:
# ¹Ô¤ò¼õ¤±¼è¤ê¡¢¥¹¥Ú¡¼¥¹Îà¤Ç»Ï¤Þ¤ë·Ñ³¹Ô¤ò·ë¹ç¤¹¤ë
sub get_line {
$thisline = $lookahead;
line: while ($lookahead = <STDIN>) {
if ($lookahead =~ /^[ \t]/) {
$thisline .= $lookahead;
}
else {
last line;
}
}
$thisline;
}
$lookahead = <STDIN>; # ºÇ½é¤Î¹Ô¤òÆÀ¤ë
while ($_
= do get_line()) {
...
}
°ú¿ô¤Ë̾Á°¤ò¤Ä¤±¤ë¤Ë¤Ï¡¢¥í¡¼¥«¥ë¤Ê¥ê¥¹¥È¤ØÇÛÎóÂåÆþ¤ò¹Ô¤¦¡£
sub maybeset { local($key, $value) = @_; $foo{$key} = $value unless $foo{$key}; }
¤³¤¦¤¹¤ë¤³¤È¤Ç¡¢»²¾È¸Æ¤Ó½Ð¤·¤¬Ã͸ƤӽФ·¤Ë¤Ê¤ë¡£ ¤Ê¤¼¤Ê¤é¡¢ÂåÆþ¤Ë¤è¤êÃͤ¬¥³¥Ô¡¼¤µ¤ì¤ë¤«¤é¤Ç¤¢¤ë¡£
¥µ¥Ö¥ë¡¼¥Á¥ó¤ÏºÆµ¢Åª¤Ë¸Æ¤Ó½Ð¤·¤Æ¤â¤è¤¤¡£
¥µ¥Ö¥ë¡¼¥Á¥ó¤ò &
·Á¼°¤Ç¸Æ¤Ó½Ð¤¹¾ì¹ç¤Ï°ú¿ô¤Î¥ê¥¹¥È¤Ï¤Ä¤±¤Ê¤¯¤Æ¤â¤è¤¤¡£
¤³¤ì¤ò¾Êά¤¹¤ë¤È¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÇÛÎó @_
¤Î¥»¥Ã¥È¥¢¥Ã¥×¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£
¥³¡¼¥ë¤ò¹Ô¤Ã¤¿»þ¤ÎÇÛÎó @_
¤¬¥µ¥Ö¥ë¡¼¥Á¥ó¤«¤é»²¾È¤Ç¤¤ë¡£
do foo(1,2,3); # 3 ¤Ä¤Î°ú¿ô¤òÅϤ¹ &foo(1,2,3); # Ʊ¤¸ do foo(); # ¥Ì¥ë¥ê¥¹¥È¤òÅϤ¹ &foo(); # Ʊ¤¸ &foo; # °ú¿ô¤òÅϤµ¤Ê¤¤ -- ¤è¤ê¸úΨ¤¬¤è¤¤
¥µ¥Ö¥ë¡¼¥Á¥ó¤ØÇÛÎó¤ÎÃͤòÅϤ¹¤Î¤Ç¤Ï¤Ê¤¯¡¢ ¤½¤Î̾Á°¤òÅϤ·¤Æ¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤¬¥í¡¼¥«¥ë¤Ê¥³¥Ô¡¼¤ËÂФ·¤Æ¤Ç¤Ï¤Ê¤¯ ¥°¥í¡¼¥Ð¥ë¤ÊÇÛÎó¤òÊѹ¹¤Ç¤¤ë¤è¤¦¤Ë¤·¤¿¤¤»þ¤¬¤¢¤ë¤À¤í¤¦¡£
perl ¤Ç¤Ï̾Á°¤ò»ý¤ÄÁ´¤Æ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¤Æ¡¢
¤½¤Î̾Á°¤ÎÁ°¤Ë *
¤ò¤Ä¤±¤ë¤³¤È¤Ç»²¾È¤¹¤ë¤³¤È¤¬¤Ç¤¤ë: *foo
¡£
¤³¤ì¤¬É¾²Á¤µ¤ì¤ë¤È¡¢¤½¤Î̾Á°¤ò»ý¤Ä¡¢
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¡¦¥Õ¥©¡¼¥Þ¥Ã¥È¡¦¥µ¥Ö¥ë¡¼¥Á¥ó¤ò´Þ¤à
Á´¥ª¥Ö¥¸¥§¥¯¥È¤òɽ¤¹¥¹¥«¥é¡¼ÃͤȤʤ롣
local()
±é»»Æâ¤ÇÂåÆþ¤ò¹Ô¤¦¤È¡¢
¤½¤Î̾Á°¤¬¤½¤ì¤ËÂåÆþ¤µ¤ì¤¿ *
ÃÍ ¤ò»²¾È¤¹¤ë¤è¤¦¤Ë¤Ê¤ë¡£Î㤨¤Ð¡¢
sub doubleary { local(*someary) = @_; foreach $elem (@someary) { $elem *= 2; } } do doubleary(*foo); do doubleary(*bar);
*name
¤Ø¤ÎÂåÆþ¤Ï
¸½ºß¤Î¤È¤³¤í local()
¤Î¾ì¹ç¤·¤«¤ª´«¤á¤Ç¤¤Ê¤¤¡£
¼ÂºÝ¤Î¤È¤³¤í¡¢*name
¤Ø¤ÎÂåÆþ¤Ï¤É¤³¤Ç¤â¤Ç¤¤ë¤Î¤À¤¬¡¢
°ÊÁ°¤Ë¹Ô¤Ã¤¿ *name
¤Ø¤Î»²¾È¤¬±Ê±ó¤ËÈø¤ò°ú¤¯(may be stranded forever)
²ÄǽÀ¤¬¤¢¤ë¡£¤³¤ì¤Ïº¤¤Ã¤¿¤³¤È¤«¤â¤·¤ì¤Ê¤¤¤·¡¢¤½¤¦¤Ç¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
¥¹¥«¥é¡¼Ãͤϲ¿¤â¤·¤Ê¤¯¤Æ¤â»²¾ÈÅϤ·¤Ç¤¢¤ë¡£
¤¹¤Ê¤ï¤Á¡¢¤³¤Î¥á¥«¥Ë¥º¥à¤òÍѤ¤¤Ê¤¯¤Æ¤â¡¢
´Ø¿´¤Î¤¢¤ë $_[nnn]
¤Ø¤ÎÌÀ¼¨Åª¤Ê»²¾È¤ò¹Ô¤¦¤³¤È¤Ç
Êѹ¹¤ò¹Ô¤¦¤³¤È¤¬²Äǽ¤Ç¤¢¤ë¡£
ÇÛÎó¤ÎÁ´Í×ÁǤò¥¹¥«¥é¡¼ÃͤȤ·¤ÆÅϤ¹¤³¤È¤ÇÇÛÎóÍ×ÁǤÎÊѹ¹¤Ï²Äǽ¤Ç¤¢¤ë¤¬¡¢
push
¡¢pop
¤äÇÛÎó¤ÎÂ礤µ¤òÊѤ¨¤ëÁàºî¤Ë¤Ï¡¢
*
¥á¥«¥Ë¥º¥à¤ò»È¤ï¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
*
¥á¥«¥Ë¥º¥à¤Ï¤É¤Î¤è¤¦¤Ê¾ì¹ç¤Ç¤â¸úΨ¤¬¤è¤ê¤è¤¤¤À¤í¤¦¡£
*name
¤ÎÃͤϽÐÎÏÉÔ²Äǽ¤Ê¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò´Þ¤à¤Î¤Ç¡¢
print
¤ä printf
¡¢
sprintf
¤Î %s
¤Ø¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤ë¤È
½ÐÎϤò¤¤ì¤¤¤Ë¹Ô¤¦¤¿¤á¡¢`*name' ¤È¤¤¤¦Ãͤˤʤ롣
ÇÛÎó¤òÊѹ¹¤·¤¿¤¯¤Ê¤¤¾ì¹ç¤Ç¤â¡¢ ¤³¤Î¥á¥«¥Ë¥º¥à¤ÏÊ£¿ô¤ÎÇÛÎó¤ò°ì¤Ä¤Î¥ê¥¹¥È¤ÇÅϤ¹¤Î¤ËÊØÍø¤Ç¤¢¤ë¡£ ¤Ê¤¼¤Ê¤é¡¢Ä̾¥ê¥¹¥È¥á¥«¥Ë¥º¥à¤ÏÁ´ÇÛÎóÃͤò°ì¤Ä¤Ë¥Þ¡¼¥¸¤¹¤ë¤¿¤á¡¢ ¤½¤ì¤ò¸Ä¡¹¤ÎÇÛÎó¤Ëʬ¤±¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¥ó¥°¤ÇÍѤ¤¤é¤ì¤ë¥Ñ¥¿¡¼¥ó¤Ï¡¢ Version 8 ¤Î regexp ¥ë¡¼¥Á¥ó¤Ç»ÈÍѤǤ¤ë¤â¤Î¤ÈƱ¤¸¤â¤Î¤Ç¤¢¤ë¡£ (¼Â¤Ï¡¢¥Ø¥ó¥ê¡¼¥¹¥Ú¥ó¥µ¡¼¤ÎºÆÇÛÉÛ¼«Í³¤Ê V8 ¥ë¡¼¥Á¥ó¤ò»È¤Ã¤Æ¤¤¤ë¡£)
¤³¤ì¤Ë²Ã¤¨¤Æ¡¢°Ê²¼¤Î¥Þ¥Ã¥Á¥ó¥°¤¬»È¤¨¤ë¡£
\w : ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥Èʸ»ú( "_" ¤ò´Þ¤à) \W : Èó¥¢¥ë¥Õ¥¡¥Ù¥Ã¥Èʸ»ú \b : ñ¸ì¤Î¶³¦ \B : Èóñ¸ì¶³¦ \s : ¥¹¥Ú¡¼¥¹Ê¸»ú(whitespace character) \S : Èó¥¹¥Ú¡¼¥¹Ê¸»ú \d : ¿ô»ú \D : Èó¿ô»ú
\w
¡¢\s
¡¢\d
¤ò character class ¤ÎÃæ¤ÇÍѤ¤¤Æ¤âÎɤ¤¡£\n
¡¢\r
¡¢\f
¡¢\t
¡¢\NNN
¤Ï
Ä̾ï¤ÈƱ¤¸°ÕÌ£¤ò»ý¤Ä¡£\b
¤Ïñ¸ì¶³¦¤Ç¤Ï¤Ê¤¯¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹¤òɽ¤¹¡£|
¤Ç¶èÀڤ롣
³ç¸Ì¹½Â¤ (
... )
¤ò»È¤¦¤È¡¢
\¿ô»ú
¤¬¤½¤Î¿ô»úÈÖÌܤÎʸ»úÎó¤Ë¥Þ¥Ã¥Á¤¹¤ë¡£
(¥Ñ¥¿¡¼¥ó¤Î³°¤Ç¤Ï¡¢
¿ô»ú¤ÎÁ°¤Ë \
¤Ç¤Ï¤Ê¤¯ $
¤ò¾ï¤ËÍѤ¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
$¿ô»ú
¤È $`
¡¢$&
¡¢$'
¤Î͸úÈϰϤÏ
³ç¸Ì¤Ç°Ï¤Þ¤ì¤¿¥Ö¥í¥Ã¥¯¤ä eval
ʸ»úÎó¡¢
¤Þ¤¿¤Ï¼¡¤Î¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Þ¤Ç¤Ç¤¢¤ë¡£
\¿ô»ú
µ½Ò¤Ï¸½ºß¤Î¥Ñ¥¿¡¼¥ó¤Î³°¤Ç¤â»È¤¨¤ë¤³¤È¤¬¤¢¤ë¤¬¡¢
¤½¤ì¤ËÍê¤ë¤Ù¤¤Ç¤Ï¤Ê¤¤¡£)
³ç¸Ì¤Ï¤¤¤¯¤ÄÍѤ¤¤Æ¤â¤è¤¤¡£
9 ¤è¤ê¿¤¯¤ÎÉôʬʸ»úÎ󤬤¢¤ë¾ì¹ç¤Ï¡¢
$10
,$11
... ¤¬Âбþ¤¹¤ëÉôʬʸ»úÎó¤ò»²¾È¤¹¤ë¡£
¥Ñ¥¿¡¼¥ó¤ÎÃæ¤Ç¤Ï¡¢\10
,\11
... ¤¬Éôʬʸ»úÎó¤ò¸åÊý»²¾È¤¹¤ë
(¾¯¤Ê¤¯¤È¤â¤½¤Î¿ô¤Îº¸³ç¸Ì¤¬¸åÊý»²¾È²Õ½ê¤ÎÁ°¤Ë¤¢¤ë¾ì¹ç¡£
¤Ê¤±¤ì¤Ð°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤È¤Î¥³¥ó¥Ñ¥Á¥Ó¥ê¥Æ¥£¤Î¤¿¤á¡¢
\10
¤Ï \010
¤¹¤Ê¤ï¤Á¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹¤ÈƱ¤¸¡¢
\11
¤Ï \011
¤¹¤Ê¤ï¤Á¥¿¥Ö¤ÈƱ¤¸¡¢¤È¤Ê¤ë¡£
\1
¤«¤é \9
¤Þ¤Ç¤Ï¾ï¤Ë¸åÊý»²¾È¤Ç¤¢¤ë¡£)¡£
$+
¤ÏºÇ¸å¤Ë¥Þ¥Ã¥Á¤·¤¿³ç¸Ì¤òÊÖ¤¹¡£
$&
¤Ï¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎóÁ´ÂΤòÊÖ¤¹¡£
($0
¤ÏƱ¤¸¤â¤Î¤òÊÖ¤·¤Æ¤¤¤¿¤¬¡¢¸½ºß¤Ï¤½¤¦¤Ç¤Ï¤Ê¤¤¡£)
$`
¤Ï¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎó¤ÎÁ°¤ÎÁ´Ê¸»ú¤òÊÖ¤¹¡£
$'
¤Ï¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎó¤Î¸å¤ÎÁ´Ê¸»ú¤òÊÖ¤¹¡£
(Îã)
s/^([^ ]*) *([^ ]*)/$2 $1/; # ºÇ½é¤Î 2 ñ¸ì¤òÆþ¤ìÂؤ¨¤ë if (/Time: (..):(..):(..)/) { $hours = $1; $minutes = $2; $seconds = $3; }
¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Ê¸»ú ^
¤Ïʸ»úÎó¤ÎºÇ½é¤Î¤ß¡¢
ʸ»ú $
¤Ïʸ»úÎó¤ÎºÇ¸å
(¤Þ¤¿¤ÏºÇ¸å¤Î²þ¹Ôʸ»ú¤ÎÁ°¤Îʸ»ú)¤Î¤ß¤Ë°ìÃפ¹¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤Æ¡¢
¤Þ¤¿¡¢perl ¤Ïʸ»úÎó¤¬ 1 ¹Ô¤·¤«´Þ¤ó¤Ç¤¤¤Ê¤¤¤È²¾Äꤷ¤ÆºÇŬ²½¤·¤Æ¤¤¤ë¡£
²þ¹Ôʸ»ú¤¬Ê£¿ô¤¢¤ë¾ì¹ç¤Î ^
¤È $
¤ÎµóÆ°¤ÏÌ·½â¤¹¤ë
(beinconsistent)¡£
¤·¤«¤·¡¢Ê¸»úÎó¤òÊ£¿ô¹Ô¤Î¥Ð¥Ã¥Õ¥¡¤È¤·¤Æ°·¤¤¡¢
^
¤¬Ê¸»úÎóÃæ¤ÎÁ´¤Æ¤Î²þ¹Ôʸ»ú¤Î¸å¤Ë¥Þ¥Ã¥Á¤·¡¢
$
¤¬Á´¤Æ¤Î²þ¹Ôʸ»ú¤ÎÁ°¤Ë¥Þ¥Ã¥Á¤¹¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤â¤¢¤ë¤À¤í¤¦¡£
¤³¤ì¤ò¼Â¸½¤¹¤ë¤Ë¤Ï¡¢¾¯¤·¥ª¡¼¥Ð¡¼¥Ø¥Ã¥É¤òÍפ¹¤ë¤¬¡¢
$*
ÊÑ¿ô¤Ë 1 ¤ò¥»¥Ã¥È¤¹¤ì¤ÐÎɤ¤¡£
¤³¤ÎÊÑ¿ô¤ò 0 ¤ËÌ᤻¤Ð¡¢perl ¤ÏËÜÍè¤ÎµóÆ°¤ËÌá¤ë¡£See section @hbox{@hbox to 1.6em{@tt@$*@hfil} : Ê£¿ô¹Ô¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¥ó¥°¤ò¹Ô¤¦¤«Èݤ«}.
Ê£¿ô¹Ô¤ÎÃÖ´¹¤òÍưפˤ¹¤ë¤¿¤á¤Ë¡¢Ê¸»ú .
¤Ï²þ¹Ôʸ»ú¤Ë¥Þ¥Ã¥Á¤·¤Ê¤¤
($*
¤¬ 0 ¤Î»þ¤Ç¤â)¡£Æäˡ¢¼¡¤ÎÎã¤Ç¤Ï¡¢$_
¤Ë²þ¹Ôʸ»ú¤ò»Ä¤¹¡£
$_ = <STDIN>; s/.*(some_string).*/$1/;
²þ¹Ôʸ»ú¤¬¤¤¤é¤Ê¤¤¤Ê¤é¡¢¼¡¤Î¤É¤ì¤«¤ò»î¤»¤ÐÎɤ¤¡£
s/.*(some_string).*\n/$1/; s/.*(some_string)[^\000]*/$1/; s/.*(some_string)(.|\n)*/$1/; chop; s/.*(some_string).*/$1/; /(some_string)/ && ($_ = $1);
Àµµ¬É½¸½¤Î³ÆÍ×ÁǤθå¤Ë¡¢
Ãæ³ç¸Ì¤Ç°Ï¤ó¤À¿ô»ú¤ò {n,m}
¤Î·Á¤ÇÉÕ¤±¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¤³¤³¤Ç n ¤Ï¤½¤ÎÍ×ÁǤ˥ޥåÁ¤¹¤ëºÇ¾®¸Â¤Î²ó¿ô¡¢
m ¤ÏºÇÂç¸Â¤Î²ó¿ô¤òɽ¤¹¡£
{n}
¤Î·Á¤Ï {n,n}
¤ÈƱÅù¤Ç¤¢¤ê¡¢
n ²ó¤Á¤ç¤¦¤É¤Ë¥Þ¥Ã¥Á¤¹¤ë¡£
{n,}
¤Î·Á¤Ï n °Ê¾å¤Î²ó¿ô¤Ë¥Þ¥Ã¥Á¤¹¤ë
(Ãæ³ç¸Ì¤¬Ê̤Υ³¥ó¥Æ¥¥¹¥È¤Ç»È¤ï¤ì¤¿¾ì¹ç¤Ï¡¢Ãæ³ç¸Ì¤ÏÄ̾ï¤Îʸ»ú¤È¤·¤Æ°·¤ï¤ì¤ë)¡£
½¤¾þ»Ò *
¤Ï {0,}
¡¢½¤¾þ»Ò +
¤Ï {1,}
¡¢
½¤¾þ»Ò ?
¤Ï {0,1}¤Ë¤½¤ì¤¾¤ìÅù¤·¤¤¡£
n ¤ä m ¤ÎÂ礤µ¤Ë¤ÏÀ©¸Â¤Ï¤Ê¤¤¤¬¡¢ Â礤ʿô¤ò»È¤¦¤È¤è¤ê¿¤¯¤Î¥á¥â¥ê¡¼¤ò¾ÃÈñ¤¹¤ë¡£
perl ¤Ç¤Ï¡¢Î㤨¤Ð \b
¡¢\w
¡¢\n
¤Î¤è¤¦¤Ë¡¢
¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤òÁ°¤ËÉÕ¤±¤ë¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤Ï
¤¹¤Ù¤Æ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç¤¢¤ë¤³¤È¤Ëµ¤¤¬¤Ä¤¯¤À¤í¤¦¡£
¾¤ÎÀµµ¬É½¸½¸À¸ì¤È°ã¤¤¡¢
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç¤Ê¤¤Ê¸»ú¤Ë¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤ò¤Ä¤±¤ë¤³¤È¤Ï¤Ê¤¤¤Î¤Ç¡¢
\\
¡¢ \(
¡¢ \)
¡¢ \<
¡¢ \>
¡¢ \{
¡¢
¤ä \}
¤Î¤è¤¦¤Ê¤â¤Î¤ÏÁ´¤Æʸ»úÄ̤ê¤Ë²ò¼á¤µ¤ì¡¢
¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤È¤Ï²ò¼á¤µ¤ì¤Ê¤¤¡£
¤³¤ì¤Ë¤è¤ê¡¢¥á¥¿¥¥ã¥é¥¯¥¿¡¼¤ò´Þ¤ó¤Ç¤¤¤ë¤Î¤Ç¤Ï¤Ê¤¤¤«¤È¿´ÇÛ¤Êʸ»úÎó¤ò
¥Ñ¥¿¡¼¥ó¤È¤·¤Æ»ÈÍѤ¹¤ë¤³¤È¤¬Íưפˤʤ롣
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç¤Ê¤¤Ê¸»ú¤Ïñ½ã¤Ë»ÈÍѤ·¤ÆÎɤ¤¡£
$pattern =~ s/(\W)/\\$1/g;
write
±é»»»Ò¤Ç»È¤¦½ÐÎϥ쥳¡¼¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï°Ê²¼¤Î¤è¤¦¤ËÀë¸À¤¹¤ë¡£
format NAME = FORMLIST .
NAME ¤ò¾Êά¤¹¤ë¤È¡¢`STDOUT' ¤¬ÄêµÁ¤µ¤ì¤ë¡£ FORMLIST ¤ÏÊ£¿ô¹Ô¤«¤é¤Ê¤ê¡¢¹Ô¤Ï¤½¤ì¤¾¤ì 3 ¼ïÎà¤Î¤É¤ì¤«¤Ç¤¢¤ë¡£
picture
¹Ô¤Ï¹ÔÆâ¤ÎÃͤ¬ÃÖ´¹¤µ¤ì¤ëÆÃÄê¤Î¥Õ¥£¡¼¥ë¥É¤ò½ü¤¤¤Æ
¸«¤¿Ìܤ½¤Î¤Þ¤Þ¤Ë½ÐÎϤµ¤ì¤ë¡£
picture
¥Õ¥£¡¼¥ë¥É¤ÏÁ´¤Æ @
¤Þ¤¿¤Ï ^
¤Ç»Ï¤Þ¤ë¡£
@
¥Õ¥£¡¼¥ë¥É(ÇÛÎó¤òɽ¤¹ @
¤Èº®Í𤷤ʤ¤¤è¤¦¤Ë)¤ÏÄ̾ï¤Î¾ì¹ç¡¢
^
¥Õ¥£¡¼¥ë¥É¤ÏÊ£¿ô¹Ô¥Æ¥¥¹¥È¥Ö¥í¥Ã¥¯¤Î
½éÊâŪ¤Ê filling ¤ò¹Ô¤¦¤¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
¥Õ¥£¡¼¥ë¥É¤ÎŤµ¤Ïʸ»ú <
>
|
¤ÇËä¤á¤ë¤³¤È¤Çɽ¤¹¡£
¤³¤ì¤é¤Ï¤½¤ì¤¾¤ìº¸´ó¤»¡¢±¦´ó¤»¡¢¥»¥ó¥¿¥ê¥ó¥°¤ò»Ø¼¨¤¹¤ë¡£
±¦´ó¤»¤Ë¤Ä¤¤¤Æ¤Ï¡¢#
(¤Ë .
¤ò¤Ä¤±¤Æ¤â¤è¤¤)¤ò»È¤Ã¤Æ
¿ôÃÍ¥Õ¥£¡¼¥ë¥É¤Ç¤¢¤ë¤³¤È¤ò»ØÄꤷ¤Æ¤â¤è¤¤¡£
(@ ¤ÎÂå¤ï¤ê¤Ë ^ ¤ò»È¤¦¤È¡¢¤½¤Î¥Õ¥£¡¼¥ë¥É¤¬ undefined ¤Î¾ì¹ç¥Ö¥é¥ó¥¯¤Ë¤Ê¤ë¡£)
¤³¤ì¤é¤Î¥Õ¥£¡¼¥ë¥É¤Ë»ØÄꤵ¤ì¤¿Ãͤ˲þ¹Ô¤¬Æþ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢
²þ¹Ô¤Þ¤Ç¤Î¥Æ¥¥¹¥È¤Î¤ß¤¬½ÐÎϤµ¤ì¤ë¡£
Æüì¤Ê¥Õ¥£¡¼¥ë¥É @*
¤ÏÊ£¿ô¹Ô¤ÎÃͤò½ÐÎϤ¹¤ë¤Î¤ËÍѤ¤¤ë¡£
¤³¤ì¤Ï°ì¹Ô¤Ë¤½¤ì¤À¤±¤·¤«»ØÄê¤Ç¤¤Ê¤¤¡£
ÃͤϤ½¤Î¼¡¤Î¹Ô¤Ç»ØÄꤹ¤ë¡£
½çÈÖ¤Ï picture
¥Õ¥£¡¼¥ë¥É¤Î¤â¤Î¤ÈƱ¤¸¤Ë¤¹¤ë¡£
Ãͤϥ³¥ó¥Þ¤Ç¶èÀÚ¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
@
¤Ç¤Ï¤Ê¤¯¡¢
^
¤Ç»Ï¤Þ¤ë picture
¥Õ¥£¡¼¥ë¥É¤ÏÆÃÊ̤˰·¤ï¤ì¤ë¡£
»ØÄꤹ¤ëÃͤϥƥ¥¹¥Èʸ»úÎó¤òÃͤȤ·¤Æ»ý¤Ä¥¹¥«¥é¡¼ÊÑ¿ô¤Î̾Á°¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
perl ¤Ï²Äǽ¤Ê¤«¤®¤ê¤Î¥Æ¥¥¹¥È¤ò¥Õ¥£¡¼¥ë¥É¤ËÍ¿¤¨¡¢ÊÑ¿ô¤ÎÀèƬ¤«¤é¤½¤ì¤ò¼è¤ê½ü¤¯¡£
¤³¤ì¤Ï¼¡¤Ë¤½¤ÎÊÑ¿ô¤¬»²¾È¤µ¤ì¤¿»þ¤Ë¥Æ¥¥¹¥È¤Î³¤¤òɽ¼¨¤¹¤ë¤¿¤á¤Ç¤¢¤ë¡£
Ä̾¥Æ¥¥¹¥È¥Ö¥í¥Ã¥¯¤ò½ÐÎϤ¹¤ë¤Ë¤Ï¿âľ¤Ê¥¹¥¿¥Ã¥¯¤ÎÃæ¤Ë¥Õ¥£¡¼¥ë¥É¤ò¤¤¤¯¤Ä¤«½ñ¤¯¡£
ºÇ¸å¤Î¥Õ¥£¡¼¥ë¥É¤ò ...
¤Ç½ª¤ï¤ë¤³¤È¤â¤Ç¤¤ë¡£
¤³¤¦¤¹¤ì¤Ð¥Æ¥¥¹¥È¤¬Á´ÉôÆþ¤ê¤¤é¤Ê¤¤¾ì¹ç¤Ë ...
¤¬½ÐÎϤ˸½¤ì¤ë¡£
ÊÑ¿ô $:
¤ò¹¥¤ß¤Îʸ»ú¤Î¥ê¥¹¥È¤ËÊѹ¹¤¹¤ë¤³¤È¤Ç
¥Æ¥¥¹¥È¤òʬ³ä¤¹¤ë¤³¤È¤¬²Äǽ¤Êʸ»ú¤òÊѤ¨¤ë¤³¤È¤¬¤Ç¤¤ë¡£
See section @hbox{@hbox to 1.6em{@tt@$:@hfil} : format ¤Çʸ»úÎó¤òʬ¤±¤ëºÝ¤ÎľÁ°¤Îʸ»úÎ󥻥åÈ}.
¥Õ¥©¡¼¥Þ¥Ã¥È¤µ¤ì¤ë¥Æ¥¥¹¥È¤¬Ã»¤¤¾ì¹ç¡¢
^
¥Õ¥£¡¼¥ë¥É¤ò»È¤¦¤È²ÄÊÑĹ¥ì¥³¡¼¥É¤¬¤Ç¤¤ë¤Î¤Ç¡¢
¹Ô¤Î¤É¤³¤«¤Ëʸ»ú ~
¤òÆþ¤ì¤ë¤³¤È¤Ç¶õ¹Ô¤Î½ÐÎϤòÍÞÀ©¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
(¸«°×¤µ¤ò¹Í¤¨¤ë¤È¡¢Ä̾²Äǽ¤Ê¤é¤ÐÀèƬ¤ËÆþ¤ì¤ë¤Ù¤¤Ç¤¢¤ë¡£)
~
¤Ï½ÐÎϤˤª¤¤¤Æ¥¹¥Ú¡¼¥¹¤ËÊÑ´¹¤µ¤ì¤ë¡£
°ì¤ÄÌܤ˳¤±¤ÆÆó¤ÄÌܤΠ~
¤òÆþ¤ì¤ë¤È¡¢
¹ÔÃæ¤ÎÁ´¥Õ¥£¡¼¥ë¥É¤¬¤Ê¤¯¤Ê¤ë¤Þ¤Ç¤½¤Î¹Ô¤ò·«¤êÊÖ¤¹?¡£
(@
¥Õ¥£¡¼¥ë¥É¤ò»È¤¦¾ì¹ç¡¢¤½¤ì¤ËÍ¿¤¨¤ë expression ¤Ï
±Ê±ó¤ËƱ¤¸ÃͤǤ¢¤ë¤è¤¦¤Ê¤â¤Î¤Ë¤¹¤ë¤Ù¤¤Ç¤Ï¤Ê¤¤¡£)
Îã:
# /etc/passwd ¥Õ¥¡¥¤¥ë¤Î¥ì¥Ý¡¼¥È format STDOUT_TOP = Passwd File Name Login Office Uid Gid Home ------------------------------------------------------------------ . format STDOUT = @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<< $name, $login, $office,$uid,$gid, $home # ¥Ð¥°¥ì¥Ý¡¼¥È·Á¼° format STDOUT_TOP = Bug Reports @<<<<<<<<<<<<<<<<<<<<<<< @||| @>>>>>>>>>>>>>>>>>>>>>>> $system, $%, $date ------------------------------------------------------------------ . format STDOUT = Subject: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $subject Index: @<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $index, $description Priority: @<<<<<<<<<< Date: @<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $priority, $date, $description From: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $from, $description Assigned to: @<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $programmer, $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<... $description .
Ʊ¤¸½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤ËÂФ·¤Æ write
¤ò»È¤Ã¤Æ
½ÐÎϤòº®ºß¤µ¤»¤ë¤³¤È¤Ï²Äǽ¤Ç¤¢¤ë¤¬¡¢
$-
(¥Ú¡¼¥¸¤Ë»Ä¤Ã¤Æ¤¤¤ë¹Ô)¤ò¼«Ê¬¤Ç°·¤ï¤Í¤Ð¤Ê¤é¤Ê¤¤¡£
See section @hbox{@hbox to 1.6em{@tt@$-@hfil} : ½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¥Ú¡¼¥¸¤Ë»Ä¤Ã¤Æ¤¤¤ë¹Ô¿ô}.
¤Û¤È¤ó¤É¤¬¶õÇò¤Ç¤¢¤ë¤è¤¦¤Ê¥Õ¥£¡¼¥ë¥É¤ò½ÐÎϤ¹¤ë¾ì¹ç¤Ï¡¢
¥ì¥³¡¼¥É¤Î´Ö¤Ç reset
±é»»»Ò¤ò»È¤¦¤³¤È¤ò¹Í¤¨¤¿Êý¤¬¤è¤¤¡£
¤è¤ê¸úΨŪ¤Ç¤¢¤ë¤À¤±¤Ç¤Ê¤¯¡¢
¥Õ¥£¡¼¥ë¥É¤òÁý¤ä¤·¤Æ¡¢½é´ü²½¤¹¤ë¤Î¤ò˺¤ì¤Æ¤·¤Þ¤¦¤È¤¤¤¦¥Ð¥°¤òËɤ²¤ë¡£
See section reset.
perl ¤Î¥×¥í¥»¥¹´ÖÄÌ¿®¤ÎǽÎϤϥС¼¥¯¥ì¥¤¤Î¥½¥±¥Ã¥Èµ¡¹½¤Ë´ð¤Å¤¤¤Æ¤¤¤ë¡£ ¥½¥±¥Ã¥È¤¬¤Ê¤¤¤Î¤Ê¤é¡¢¤³¤Î¹à¤ÏÆɤޤʤ¯¤Æ¤è¤¤¡£
´Ø¿ô¤ÏÂбþ¤¹¤ë¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÈƱ¤¸Ì¾Á°¤¬¤Ä¤¤¤Æ¤¤¤ë¤¬¡¢ °ú¿ô¤ÏÆó¤Ä¤ÎÍýͳ¤Ç°ã¤¦¾ì¹ç¤¬¤¢¤ë¡£ ¤Þ¤º¡¢perl ¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï C ¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤ÏƯ¤¤¬°ã¤¦¡£ ¼¡¤Ë¡¢perl ¤Ïʸ»úÎóŤòÃΤäƤ¤¤ë¤Î¤Ç¡¢¤½¤Î¾ðÊó¤ÏÅϤµ¤Ê¤¯¤Æ¤è¤¤¡£
°Ê²¼¤Ë¥¯¥é¥¤¥¢¥ó¥È¤Î¥µ¥ó¥×¥ë¤ò¼¨¤¹(¥Æ¥¹¥È¤·¤Æ¤¤¤Ê¤¤)¡£
($them,$port) = @ARGV; $port = 2345 unless $port; $them = 'localhost' unless $them; $SIG{'INT'} = 'dokill'; sub dokill { kill 9,$child if $child; } require 'sys/socket.ph'; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them); $this = pack($sockaddr, &AF_INET, 0, $thisaddr); $that = pack($sockaddr, &AF_INET, $port, $thataddr); socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; connect(S, $that) || die "connect: $!"; select(S); $| = 1; select(stdout); if ($child = fork) { while (<>) { print S; } sleep 3; do dokill(); } else { while (<S>) { print; } }
¤½¤·¤Æ¤³¤ì¤¬¥µ¡¼¥Ð¡¼¤Ç¤¢¤ë¡£
($port) = @ARGV; $port = 2345 unless $port; require 'sys/socket.ph'; $sockaddr = 'S n a4 x8'; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; $this = pack($sockaddr, &AF_INET, $port, "\0\0\0\0"); select(NS); $| = 1; select(stdout); socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; listen(S, 5) || die "connect: $!"; select(S); $| = 1; select(stdout); for (;;) { print "Listening again\n"; ($addr = accept(NS,S)) || die $!; print "accept ok\n"; ($af,$port,$inetaddr) = unpack($sockaddr,$addr); @inetaddr = unpack('C4',$inetaddr); print "$af $port @inetaddr\n"; while (<NS>) { print; print NS; } }
°Ê²¼¤Î̾Á°¤ÎÊÑ¿ô¤Ï perl ¤Ë¤ª¤¤¤ÆÆÃÊ̤ʰÕÌ£¤ò¤â¤Ä¡£ ¤³¤Î¤¦¤Á´ö¤Ä¤«¤Ï¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Î̾Á°¤ò»ý¤¿¤»¤Æ¤âÎɤ«¤Ã¤¿¤Î¤À¤¬¡¢ Á´ÊÑ¿ô¤ò `a-zA-Z' ¤Ç¥ê¥»¥Ã¥È¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¤¿¤á¡¢ ¤½¤¦¤Ï¤·¤Ê¤«¤Ã¤¿¡£ ¤³¤Î¤¿¤á¡¢¤ï¤±¤Îʬ¤«¤é¤Ê¤¤¥·¥ó¥Ü¥ë̾¤Ç¶ìÏ«¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
¤Û¤È¤ó¤É¤Î¤â¤Î¤Ï¤½¤ì¤Ê¤ê¤Ë³Ð¤¨°×¤¤¤â¤Î¤Þ¤¿¤Ï¥·¥§¥ëÊÑ¿ô¤È»÷¤¿¤â¤Î¤Ë¤·¤Æ¤¢¤ë¡£
$_
: ÆþÎϤª¤è¤Ó¥Ñ¥¿¡¼¥ó¸¡º÷¤Ë¤ª¤±¤ë¥Ç¥Õ¥©¥ë¥È¡£
¼¡¤Î¼°¤Î¥Ú¥¢¤Ï¤½¤ì¤¾¤ìÅù²Á¤Ç¤¢¤ë¡£
while (<>) { ... # only equivalent in while! while ($_ = <>) { ... /^Subject:/ $_ =~ /^Subject:/ y/a-z/A-Z/ $_ =~ y/a-z/A-Z/ chop chop($_)
³Ð¤¨Êý:
(underline is understood in certain operations.)
$.
: ºÇ¸å¤ËÆɤ߹þ¤ß¤ò¹Ô¤Ã¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¸½ºß¤Î¹ÔÈֹ档
»²¾È¤Î¤ß²Äǽ¡£¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òÌÀ¼¨Åª¤Ë¥¯¥í¡¼¥º¤·¤¿»þ¤Î¤ß¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
<>
¤ÏÌÀ¼¨Åª¤Ê¥¯¥í¡¼¥º¤ò¹Ô¤ï¤Ê¤¤¤Î¤Ç¡¢
ARGV
¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç¤¤¤¯¤È¡¢¹ÔÈÖ¹æ¤Ï¤É¤ó¤É¤óÁý²Ã¤¹¤ë¡£
( eof
¤ÎÎã¤ò»²¾È¡£)See section eof.
³Ð¤¨Êý:
¿¤¯¤Î¥×¥í¥°¥é¥à¤Ë¤ª¤¤¤Æ `.' ¤Ï¸½ºß¤Î¹ÔÈÖ¹æ¤ò¼¨¤¹¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
$/
: ÆþÎϥ쥳¡¼¥É¤Î¥»¥Ñ¥ì¡¼¥¿¡£¥Ç¥Õ¥©¥ë¥È¤Ï newline ¡£
awk ¤ÎÊÑ¿ô RS ¤Î¤è¤¦¤ÊƯ¤¤ò¤¹¤ë¡£ ¥Ì¥ëʸ»úÎó¤ò¥»¥Ã¥È¤¹¤ë¤È¡¢¥Ö¥é¥ó¥¯¹Ô¤ò¶èÀÚ¤ê¤È¤¹¤ëÅÀ¤âƱ¤¸¤Ç¤¢¤ë¡£ Ê£¿ôʸ»ú¤«¤é¤Ê¤ëʸ»úÎó¤ò¥»¥Ã¥È¤·¤Æ¡¢ Ê£¿ôʸ»ú¤Î¥Ç¥ê¥ß¥Ã¥¿¤Ë¥Þ¥Ã¥Á¤µ¤»¤ë¤³¤È¤â²Äǽ¤Ç¤¢¤ë¡£
Ãí°Õ: ¥Õ¥¡¥¤¥ë¤¬Ï¢Â³¤·¤Æ¶õ¹Ô¤ò´Þ¤à¾ì¹ç¡¢
$/
¤ò "\n\n"
¤Ë¥»¥Ã¥È¤¹¤ë¤Î¤È¡¢
""
¤Ë¥»¥Ã¥È¤¹¤ë¤Î¤È¤Ç¤Ï¾¯¤·°ÕÌ£¤¬°Û¤Ê¤ë¡£
""
¤Ë¥»¥Ã¥È¤¹¤ë¤È¡¢2 ¹Ô°Ê¾å¤ÎϢ³¤¹¤ë¶õ¹Ô¤ò 1 ¹Ô¤Î¶õ¹Ô¤È¤·¤Æ°·¤¦¡£
"\n\n"
¤Ë¥»¥Ã¥È¤¹¤ë¤È¡¢
¼¡¤Îʸ»ú¤Ï(¤½¤ì¤¬²þ¹Ôʸ»ú¤Ç¤¢¤Ã¤Æ¤â)¼¡¤Î¥Ñ¥é¥°¥é¥Õ¤Î°ìÉô¤Ç¤¢¤ë¤Èñ½ã¤Ë¸«¤Ê¤¹¡£
³Ð¤¨Êý:
`/' ¤Ï»í¤ò°úÍѤ¹¤ë»þ¡¢¹Ô¤Î¶³¦¤òʬ¤±¤ë¤Î¤Ë»È¤ï¤ì¤ë¡£
$,
: ¥³¥ó¥Þ¤Ç¶èÀڤä¿ print
´Ø¿ô¤Î°ú¿ô¤Î½ÐÎÏ¥»¥Ñ¥ì¡¼¥¿
Ä̾
print
¤Ï¥³¥ó¥Þ¤Ç¶èÀÚ¤é¤ì¤¿¥Õ¥£¡¼¥ë¥É¤ò¤½¤Î¤Þ¤Þ(²¿¤â¤Ä¤±¤º¤Ë)½ÐÎϤ¹¤ë¡£
awk ¤Î¤è¤¦¤Ë½ÐÎϤ¹¤ë¤Ë¤Ï¡¢awk ÊÑ¿ô OFS ¤Ë¥»¥Ã¥È¤¹¤ëÃÍ
(¥Õ¥£¡¼¥ë¥É´Ö¤ò²¿¤Ç¶èÀڤ뤫)¤ò¤³¤ÎÊÑ¿ô¤Ë¥»¥Ã¥È¤¹¤ë¡£
³Ð¤¨Êý:
print
´Ø¿ô¤Ë¤ª¤¤¤Æ `,' ¤Ç¶èÀÚ¤ë¤È½ÐÎϤµ¤ì¤ëʸ»ú¡£
$"
: ÇÛÎóÃͤò "" ¤Ç°Ï¤ó¤À»þ¤ËÍ×ÁÇ´Ö¤ËÆþ¤ë¥»¥Ñ¥ì¡¼¥¿
ÇÛÎóÃͤ¬ "
¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤ËÊÑ´¹¤µ¤ì¤ë»þ
(¤Þ¤¿¤ÏƱÍͤËÊÑ´¹¤µ¤ì¤ëʸ»úÎó)¤ËŬÍѤµ¤ì¤ëÅÀ¤ò½ü¤¤¤Æ¡¢
$,
¤ÈƱ¤¸¡£¥Ç¥Õ¥©¥ë¥È¤Ï¥¹¥Ú¡¼¥¹¡£
³Ð¤¨Êý:
ÌÀ¤é¤«¤À¤È»×¤¦¤Î¤À¤¬¡£
$\
: print ´Ø¿ô¤ÎºÇ¸å¤Ë½ÐÎϤ¹¤ë¥»¥Ñ¥ì¡¼¥¿
Ä̾print
¤Ï¥³¥ó¥Þ¤Ç¶èÀÚ¤é¤ì¤¿¥Õ¥£¡¼¥ë¥É¤ò½ÐÎϤ¹¤ë»þ¡¢
ºÇ¸å¤Ë newline ¤ä¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤ò¤Ä¤±¤º¤Ë½ÐÎϤ¹¤ë¡£
awk ¤Î¤è¤¦¤Ë½ÐÎϤ¹¤ë¤Ë¤Ï¡¢awk ¤Î ORS ÊÑ¿ô¤Ë¥»¥Ã¥È¤¹¤ëÃÍ
(print
¤ÎºÇ¸å¤Ë²¿¤ò½ÐÎϤ¹¤ë¤«)¤ò¤³¤ÎÊÑ¿ô¤Ë¥»¥Ã¥È¤¹¤ë¡£
³Ð¤¨Êý:
print
¤ÎºÇ¸å¤Ë \n
¤ò¤Ä¤±¤ëÂؤï¤ê¤Ë $\
¤ò¥»¥Ã¥È¤¹¤ë¡£
¤Þ¤¿¡¢`\' ¤Ï `/' ¤È»÷¤Æ¤¤¤ë¤¬¡¢
¤½¤ì¤Ï"µÕ¤Ë" perl ¤«¤é¥Ç¡¼¥¿¤ò¼õ¤±¼è¤ë»þ¤Ë»È¤¦¡£
$#
: ¿ô»ú¤Î½ÐÎÏ¥Õ¥©¡¼¥Þ¥Ã¥È
¤³¤ÎÊÑ¿ô¤Ï¡¢
awk ¤Î OFMT ÊÑ¿ô¤òÉÔ´°Á´¤Ë¥¨¥ß¥å¥ì¡¼¥È¤·¤è¤¦¤È¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
¤À¤¬¡¢awk ¤È perl ¤Ç"²¿¤¬¿ôÃͤ«"¤òȽÃǤ¹¤ëºÝ¤Ë°ã¤¤¤¬½Ð¤ë¤³¤È¤¬¤¢¤ë¡£
¤Þ¤¿¡¢½é´üÃÍ¤Ï %.6g
¤Ç¤Ï¤Ê¤¯ %.20g
¤Ç¤¢¤ë¤Î¤Ç¡¢
awk ¤ÈƱ¤¸½ÐÎϤòÆÀ¤ë¤Ë¤Ï¡¢$#
¤ò¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ë¡£
³Ð¤¨Êý:
`#' ¤Ï¿ô¤òɽ¤¹¡£
$%
: ¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¸½ºß¤Î¥Ú¡¼¥¸Èֹ档
³Ð¤¨Êý:
nroff ¤Ë¤ª¤¤¤Æ `%' ¤Ï¥Ú¡¼¥¸ÈÖ¹æ¤Ç¤¢¤ë¡£
$=
: ¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¸½ºß¤Î¥Ú¡¼¥¸Ä¹¤µ
(½ÐÎϲÄǽ¹Ô¿ô)¡£
¥Ç¥Õ¥©¥ë¥È¤Ï 60¡£
³Ð¤¨Êý:
`=' ¤Ï¿åÊ¿¤ÊÀþ¤«¤é¤Ç¤¤Æ¤¤¤ë¡£
$-
: ¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¥Ú¡¼¥¸¤Ë»Ä¤Ã¤Æ¤¤¤ë¹Ô¿ô¡£
³Ð¤¨Êý:
¥Ú¡¼¥¸¤Î¹Ô¿ô - ½ÐÎϤ·¤¿¹Ô¿ô¡£
$~
: ¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î
¸½ºß¤Î¥ì¥Ý¡¼¥È¥Õ¥©¡¼¥Þ¥Ã¥È¤Î̾Á°¡£
¥Ç¥Õ¥©¥ë¥È¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë̾¡£
³Ð¤¨Êý:
$^
¤Î·»Äï¡£
$^
: ¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤Î¸½ºß¤Î¥Ú¡¼¥¸¥È¥Ã¥×¤Î̾Á°¡£
¥Ç¥Õ¥©¥ë¥È¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë̾¤Ë `_TOP' ¤ò¤Ä¤±¤¿¤â¤Î¡£
³Ð¤¨Êý:
¥Ú¡¼¥¸¤Î¥È¥Ã¥×¤ò»Ø¤·¤Æ¤¤¤ë¡£
$|
: write
¤Þ¤¿¤Ï print
¤Î¸å¤Ë¥Õ¥é¥Ã¥·¥å¤ò¹Ô¤¦¤«Èݤ«
Èó 0 ¤Ë¥»¥Ã¥È¤¹¤ë¤È¡¢¸½ºß¥»¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤ë½ÐÎÏ¥Á¥ã¥ó¥Í¥ë¤ËÂФ¹¤ë
Á´¤Æ¤Î write
¤Þ¤¿¤Ï print
¤Î¸å¤Ë¥Õ¥é¥Ã¥·¥å¤ò¹Ô¤¦¡£
¥Ç¥Õ¥©¥ë¥È¤Ï 0 ¤Ç¤¢¤ë¡£
STDOUT
¤ÏüËö¤Ø¤Î½ÐÎϤϹԥХåե¡¥ê¥ó¥°¤µ¤ì¡¢
¤½¤ì°Ê³°¤Ï¥Ö¥í¥Ã¥¯¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤ë¤³¤È¤ËÃí°Õ¡£
¤³¤ÎÊÑ¿ô¤ò¥»¥Ã¥È¤¹¤ë¤È¡¢perl ¥¹¥¯¥ê¥×¥È¤ò rsh ¤Î²¼¤ÇÁö¤é¤»¤Æ¡¢
²¿¤¬µ¯¤³¤Ã¤Æ¤¤¤ë¤«¤ò¤½¤Î»þ¤Ë¸«¤¿¤¤¾ì¹ç¤Ê¤É¡¢¥Ñ¥¤¥×¤Ë½ÐÎϤ¹¤ëºÝ¤ËÊØÍø¤Ç¤¢¤ë¡£
³Ð¤¨Êý:(?)
(when you want your pipes to be piping hot.)
$$
: ¥¹¥¯¥ê¥×¥È¤òÁö¤é¤»¤Æ¤¤¤ë perl ¤Î¥×¥í¥»¥¹Èֹ档
³Ð¤¨Êý:
¥·¥§¥ë¤ÈƱ¤¸¡£
$?
: ºÇ¸å¤Î¥Ñ¥¤¥×¤Î¥¯¥í¡¼¥º¡¢`¥³¥Þ¥ó¥É`
¡¢
system
´Ø¿ô¤«¤éÊ֤ä¿¥¹¥Æ¡¼¥¿¥¹¡£
¤³¤ì¤Ï¥·¥¹¥Æ¥à¥³¡¼¥ë wait()
¤«¤éÊ֤ä¿¥¹¥Æ¡¼¥¿¥¹¥ï¡¼¥É¤Ç¤¢¤ê¡¢
¥µ¥Ö¥×¥í¥»¥¹¤Î¼ÂºÝ¤Î½ªÎ»ÃÍ¤Ï $? >> 8
¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¡£
$? & 255
¤Ë¤è¤ê¡¢¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ë¸¶°ø¤È¤Ê¤Ã¤¿¥·¥°¥Ê¥ë(¤â¤·¤¢¤ì¤Ð)¡¢
¤ª¤è¤Ó¥³¥¢¥À¥ó¥×¤¬¤¢¤Ã¤¿¤«¤É¤¦¤«¤¬ÆÀ¤é¤ì¤ë¡£
³Ð¤¨Êý:
`sh' ¤ª¤è¤Ó `ksh' ¤ÈƱ¤¸¡£
$&
: ºÇ¸å¤ËÀ®¸ù¤·¤¿¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ç¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎó¡£
¥Ö¥í¥Ã¥¯¤ä¸½ºß¤Î¥Ö¥í¥Ã¥¯¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë eval
¤ÎÃæ¤Î¥Þ¥Ã¥Á¤Ï
Á´¤¯¥«¥¦¥ó¥È¤·¤Æ¤¤¤Ê¤¤¡£
³Ð¤¨Êý:
¤¤¤¯¤Ä¤«¤Î¥¨¥Ç¥£¥¿¤Ë¤ª¤±¤ë `&' ¤ÈƱ¤¸¡£
$`
: ºÇ¸å¤ËÀ®¸ù¤·¤¿¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ç¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎó¤ÎÁ°¤Îʸ»úÎó¡£
¥Ö¥í¥Ã¥¯¤ä¸½ºß¤Î¥Ö¥í¥Ã¥¯¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë eval
¤ÎÃæ¤Î¥Þ¥Ã¥Á¤Ï
Á´¤¯¥«¥¦¥ó¥È¤·¤Æ¤¤¤Ê¤¤¡£
³Ð¤¨Êý:
``' ¤Ï°úÍÑʸ»úÎó¤ÎÁ°¤ËÍè¤ë¤³¤È¤¬Â¿¤¤¡£
$'
: ºÇ¸å¤ËÀ®¸ù¤·¤¿¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ç¥Þ¥Ã¥Á¤·¤¿Ê¸»úÎó¤Î¸å¤Ë³¤¯Ê¸»úÎó¡£
¥Ö¥í¥Ã¥¯¤ä¸½ºß¤Î¥Ö¥í¥Ã¥¯¤Ç°Ï¤Þ¤ì¤Æ¤¤¤ë eval
¤ÎÃæ¤Î¥Þ¥Ã¥Á¤Ï
Á´¤¯¥«¥¦¥ó¥È¤·¤Æ¤¤¤Ê¤¤¡£
³Ð¤¨Êý:
`'' ¤Ï°úÍÑʸ»úÎó¤Î¸å¤ËÍè¤ë¤³¤È¤¬Â¿¤¤¡£
(Îã)
$_ = 'abcdefghi'; /def/; print "$`:$&:$'\n"; # prints abc:def:ghi
$+
: ºÇ¸å¤Î¸¡º÷¥Ñ¥¿¡¼¥ó¤Ë¤ª¤¤¤Æ¥Þ¥Ã¥Á¤·¤¿ºÇ¸å¤Î³ç¸Ì¡£
Ê£¿ô¸õÊä¤Î¥Ñ¥¿¡¼¥ó¸¡º÷¤Ç¡¢ ¤É¤Á¤é¤¬¥Þ¥Ã¥Á¤·¤¿¤«¤¬¤ï¤«¤é¤Ê¤¤¤È¤¤ËÊØÍø¤Ç¤¢¤ë¡£
(Îã)
/Version: (.*)|Revision: (.*)/ && ($rev = $+);
³Ð¤¨Êý: ?
be positive and forward looking.
$*
: Ê£¿ô¹Ô¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¥ó¥°¤ò¹Ô¤¦¤«Èݤ«
¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤òºÇŬ²½¤¹¤ë¤¿¤á¤Ë¡¢ ʸ»úÎóÆâ¤ÇÊ£¿ô¹Ô¥Þ¥Ã¥Á¥ó¥°¤ò¹Ô¤¦»þ 1 ¤Ë¥»¥Ã¥È¤·¡¢ ʸ»úÎó¤¬ 1 ¹Ô¤·¤«´Þ¤Þ¤Ê¤¤¤³¤È¤ò perl ¤ËÃΤ餻¤ë¤¿¤á¤Ë 0 ¤ò¥»¥Ã¥È¤¹¤ë¡£
$*
¤ò 0 ¤Ë¤·¤Æ¤¤¤ë¤È¡¢
newline ¤òÊ£¿ô´Þ¤àʸ»úÎó¤ËÂФ¹¤ë¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ïº®Í𤷤¿·ë²Ì¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Ï 0 ¤Ç¤¢¤ë¡£
³Ð¤¨Êý:
`*' ¤ÏÊ£¿ô¤Ë¥Þ¥Ã¥Á¤¹¤ë¡£
Ãí°Õ: ¤³¤ÎÊÑ¿ô¤Ï ^
¤ä $
¤Î²ò¼á¤Ë¤Î¤ß±Æ¶Á¤òÍ¿¤¨¤ë¡£
²þ¹Ôʸ»ú¤Ï $* == 0
¤Ç¤¢¤Ã¤Æ¤â¸¡º÷¤Ç¤¤ë¡£
$0
: ¼Â¹Ô¤·¤Æ¤¤¤ë perl ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£
$0 ¤ËÂåÆþ¤ò¹Ô¤¦¤È¡¢ps(1) ¥×¥í¥°¥é¥à¤¬»²¾È¤¹¤ë°ú¿ôÎΰè¤òÊѹ¹¤¹¤ë¡£
³Ð¤¨Êý:
sh
¤ä ksh
¤ÈƱ¤¸¡£
$¿ô»ú
: ºÇ¸å¤Ë¹Ô¤Ã¤¿¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Î³ç¸Ì¤Î¿ô¤ËÂбþ¤·¤¿¥µ¥Ö¥Ñ¥¿¡¼¥ó¡£
´û¤Ë¼Â¹Ô¤ò½ª¤¨¤¿¥Í¥¹¥È¥Ö¥í¥Ã¥¯Æâ¤Î¥Ñ¥¿¡¼¥ó¤Ï¥«¥¦¥ó¥È¤µ¤ì¤Ê¤¤¡£
³Ð¤¨Êý:
\¿ô»ú
¤Ë»÷¤Æ¤¤¤ë¡£
$[
: ÇÛÎó¤ÎºÇ½é¤ÎÍ×ÁǤ䥵¥Ö¥¹¥È¥ê¥ó¥°¤ÎºÇ½é¤Îʸ»ú¤Îź¤¨»ú¡£
¥Ç¥Õ¥©¥ë¥È¤Ï0 ¤À¤¬¡¢perl ¤ò awk (¤Þ¤¿¤Ï Fortran)¤Î¤è¤¦¤ËÆ°¤«¤·¤¿¤±¤ì¤Ð¡¢
ź¤¨»ú¤ò»È¤¦»þ¡¢
index()
¤ä substr()
¤ò¼Â¹Ô¤¹¤ë»þ¤Ë 1 ¤Ë¥»¥Ã¥È¤¹¤ì¤Ð¤è¤¤¡£
³Ð¤¨Êý:
`[' ¤Ïź¤¨»ú¤Î»Ï¤Þ¤ê¡£
$]
: `perl -v' ¤òÆþÎϤ·¤¿»þ¤Ë½ÐÎϤµ¤ì¤ëʸ»úÎó¡£
¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤·¤Æ¤¤¤ë perl ¥¤¥ó¥¿¥×¥ê¥¿¤¬ Àµ¤·¤¤¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò¥¹¥¯¥ê¥×¥È¤ÎºÇ½é¤ÇÄ´¤Ù¤ë¤Î¤Ë»È¤¨¤ë¡£ ¿ôÃͤΥ³¥ó¥Æ¥¥¹¥È¤ÇÍѤ¤¤ë¤È¡¢`version + patchlevel / 1000' ¤òÊÖ¤¹¡£
(Îã)
# getc ¤¬»È¤¨¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë ($version,$patchlevel) = $] =~ /(\d+\.\d+).*\nPatch level: (\d+)/; print STDERR "(No filename completion available.)\n" if $version * 1000 + $patchlevel < 2016;
¤Þ¤¿¤Ï¡¢¿ôÃͤȤ·¤ÆÍѤ¤¤ë¤È¡¢
warn "No checksumming!\n" if $] < 3.019;
³Ð¤¨Êý: ?
(Is this version of perl in the right bracket?)
$;
: ¿¼¡¸µÇÛÎó¤Î¥¨¥ß¥å¥ì¡¼¥·¥ç¥ó¤ÎºÝ¤Îź¤¨»ú¤Î¶èÀڤꡣ
Ï¢ÁÛÇÛÎó¤ÎÍ×ÁǤò
$foo{$a,$b,$c}
¤Î¤è¤¦¤Ë»²¾È¤¹¤ì¤Ð¡¢¤½¤ì¤Ï¼ÂºÝ¤Ï
$foo{join($;, $a, $b, $c)}
¤ò°ÕÌ£¤¹¤ë¡£
¤·¤«¤·¡¢
@foo{$a,$b,$c} # a slice--note the @
¤ÏÂÌÌܤǤ¢¤ë¡£¤Ê¤¼¤Ê¤é¡¢¤³¤ì¤Ï
($foo{$a},$foo{$b},$foo{$c})
¤ò°ÕÌ£¤¹¤ë¤«¤é¤Ç¤¢¤ë¡£
¥Ç¥Õ¥©¥ë¥È¤Ï \034
¤Ç¡¢awk ¤Î SUBSEP ¤ÈƱ¤¸¤Ç¤¢¤ë¡£
Ï¢ÁÛÇÛÎó¤Î¥¡¼¤Ë¥Ð¥¤¥Ê¥ê¡¼¥Ç¡¼¥¿¤¬´Þ¤Þ¤ì¤ë¾ì¹ç¤Ï¡¢
$;
¤È¤·¤Æ°ÂÁ´¤ÊÃͤϤʤ¤¡£
³Ð¤¨Êý:
¥³¥ó¥Þ(ʸˡŪ¤Êź¤¨»ú¶èÀÚ¤ê)¤Ï¥»¥ß-¥»¥ß¥³¥í¥ó¤Ç¤¢¤ë¡£
¤¤¤ä¡¢¤Á¤ç¤Ã¤È¶ñ¹ç¤¬°¤¤¤Î¤Ï¤ï¤«¤Ã¤Æ¤ë¤ó¤À¤±¤É¡¢
$,
¤Ï¤â¤¦¤Û¤«¤Î¤â¤Ã¤È½ÅÍפʤâ¤Î¤Ë»È¤Ã¤Æ¤·¤Þ¤Ã¤¿¤«¤é¤Í¡£
$!
: errno ¤Î¸½ºßÃͤޤ¿¤Ï¥·¥¹¥Æ¥à¥¨¥é¡¼Ê¸»úÎó
¿ôÃͤΥ³¥ó¥Æ¥¥¹¥È¤Ç»È¤¦¤È¡¢
Ä̾ï½Ð¤µ¤ì¤ë·Ù¹ð¤È¶¦¤Ë errno ¤Î¸½ºß¤ÎÃͤòÊÖ¤¹¡£
(¤Ä¤Þ¤ê¡¢¥·¥¹¥Æ¥à¥¨¥é¡¼¤ò¼¨¤¹ÆÃÄê¤Î¥¨¥é¡¼¤¬Ê֤俤ΤǤʤ¤¤«¤®¤ê¡¢
$!
¤ÎÃͤϰÕÌ£¤¬¤Ê¤¤¤³¤È¤Ë¤Ê¤ë¡£)
ʸ»úÎó¤Î¥³¥ó¥Æ¥¥¹¥È¤Ç»È¤¦¤È¡¢¥·¥¹¥Æ¥à¥¨¥é¡¼Ê¸»úÎó¤òÊÖ¤¹¡£
errno ¤ò¥»¥Ã¥È¤¹¤ë¤¿¤á¤Ë $!
¤ËÂåÆþ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
Î㤨¤Ð¡¢$!
¤Ë¥¨¥é¡¼ n ¤ËÂбþ¤¹¤ëʸ»úÎó¤òÆþ¤ì¤ÆÊÖ¤¹¾ì¹ç¡¢
¤Þ¤¿¤Ï die
´Ø¿ô¤Î½ªÎ»Ãͤò¥»¥Ã¥È¤·¤¿¤¤¾ì¹ç¡¢¤Ê¤É¡£
³Ð¤¨Êý:
What just went bang?
$@
: ºÇ¸å¤Ë¹Ô¤Ã¤¿ eval
¥³¥Þ¥ó¥É¤Î¥·¥ó¥¿¥Ã¥¯¥¹¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¡£
¥Ì¥ë¤Ê¤é¤Ð¡¢ºÇ¸å¤Ë¹Ô¤Ã¤¿ eval
¤Ï²òÀÏ¡¦¼Â¹Ô¤¬Àµ¤·¤¯¹Ô¤ï¤ì¤¿¤³¤È¤ò¼¨¤¹¡£
(µ¯Æ°¤·¤¿½èÍý¤ÏÉáÄÌ¤Ë [in a normal fashion] ¼ºÇÔ¤·¤¿¤«¤â¤·¤ì¤Ê¤¤¤¬)
³Ð¤¨Êý:
Where was the syntax error "at"?
$<
: ¥×¥í¥»¥¹¤Î¼Â uid¡£
³Ð¤¨Êý:
setuid ¥¹¥¯¥ê¥×¥È¤òÁö¤é¤»¤Æ¤¤¤ë¾ì¹ç¡¢·¯¤Ï¤É¤³¤«¤éÍ褿¤Î¤«?
$>
: ¥×¥í¥»¥¹¤Î¼Â¸ú uid¡£
(Îã)
$< = $>; # ¼Â uid ¤ò¼Â¸ú uid ¤Ë¥»¥Ã¥È¤¹¤ë ($<,$>) = ($>,$<); # ¼Â uid ¤È¼Â¸ú uid ¤òÆþ¤ìÂؤ¨¤ë
³Ð¤¨Êý:
setuid ¥¹¥¯¥ê¥×¥È¤òÁö¤é¤»¤Æ¤¤¤ë¾ì¹ç¡¢·¯¤Ï¤É¤³¤Ø¹Ô¤Ã¤¿¤Î¤«?
(Ãí°Õ)
$<
¤ä $>
¤Ï¡¢
setreuid()
¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥Þ¥·¥ó¤Ç¤Î¤ß swap ¤Ç¤¤ë¡£
$(
: ¥×¥í¥»¥¹¤Î¼Â gid¡£
Ʊ»þ¤ËÊ£¿ô¤Î¥°¥ë¡¼¥×¤Ë°¤¹¤ë¤³¤È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥Þ¥·¥ó¤Ç¤Ï¡¢ ¥¹¥Ú¡¼¥¹¤Ç¶èÀÚ¤é¤ì¤¿¥æ¡¼¥¶¤¬Â°¤·¤Æ¤¤¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤È¤Ê¤ë¡£ ºÇ½é¤Î¤â¤Î¤Ï getgid() ¤ÇÆÀ¤é¤ì¤ë¤â¤Î¤Ç¤¢¤ë¡£ »Ä¤ê¤Ï getgroups() ¤ÇÆÀ¤é¤ì¤ë¤â¤Î¤Ç¤¢¤ê¡¢ ¤½¤ÎÆâ¤Î°ì¤Ä¤ÏºÇ½é¤Î¤â¤Î¤ÈƱ¤¸¤«¤âÃΤì¤Ê¤¤¡£
³Ð¤¨Êý:
³ç¸Ì¤Ï¡¢¤â¤Î¤ò¥°¥ë¡¼¥×²½¤¹¤ë¤Î¤Ë»È¤¦¡£
setgid ¥×¥í¥°¥é¥à¤òÁö¤é¤»¤Æ¤¤¤ë¾ì¹ç¡¢
¼Â gid ¤È¤Ï¡¢¤¢¤Ê¤¿¤¬»Ä¤·¤Æ(left = º¸)Í褿¥°¥ë¡¼¥×¤Ç¤¢¤ë¡£
$)
: ¥×¥í¥»¥¹¤Î¼Â¸ú gid¡£
Ʊ»þ¤ËÊ£¿ô¤Î¥°¥ë¡¼¥×¤Ë°¤¹¤ë¤³¤È¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥Þ¥·¥ó¤Ç¤Ï¡¢ ¥¹¥Ú¡¼¥¹¤Ç¶èÀÚ¤é¤ì¤¿¥æ¡¼¥¶¤¬Â°¤·¤Æ¤¤¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤È¤Ê¤ë¡£ ºÇ½é¤Î¤â¤Î¤Ï getegid() ¤ÇÆÀ¤é¤ì¤ë¤â¤Î¤Ç¤¢¤ë¡£ »Ä¤ê¤Ï getgroups() ¤ÇÆÀ¤é¤ì¤ë¤â¤Î¤Ç¤¢¤ê¡¢ ¤½¤ÎÆâ¤Î°ì¤Ä¤ÏºÇ½é¤Î¤â¤Î¤ÈƱ¤¸¤«¤âÃΤì¤Ê¤¤¡£
³Ð¤¨Êý:
³ç¸Ì¤Ï¡¢¤â¤Î¤ò¥°¥ë¡¼¥×²½¤¹¤ë¤Î¤Ë»È¤¦¡£
setgid ¥×¥í¥°¥é¥à¤òÁö¤é¤»¤Æ¤¤¤ë¾ì¹ç¡¢
¼Â¸ú gid ¤È¤Ï¡¢¤¢¤Ê¤¿¤Ë¤È¤Ã¤ÆÀµÅö¤Ê(right = ±¦)¥°¥ë¡¼¥×¤Ç¤¢¤ë¡£
(Ãí°Õ)
$<
¡¢$>
¡¢$(
¡¢$)
¤Ï
Âбþ¤¹¤ë set[re][ug]id() ¥ë¡¼¥Á¥ó¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥Þ¥·¥ó¤Ç¤Î¤ß¥»¥Ã¥È¤µ¤ì¤ë¡£
$(
¤È $)
¤Ï¡¢
setregid() ¤ò¥µ¥Ý¡¼¥È¤¹¤ë¥Þ¥·¥ó¤Ç¤Î¤ß swap ¤Ç¤¤ë¡£
$:
: format ¤Çʸ»úÎó¤òʬ¤±¤ëºÝ¤ÎľÁ°¤Îʸ»úÎ󥻥åÈ
format
¤Ë¤ª¤¤¤Æ¡¢Ê¸»úÎó¤¬Ê¬¤±¤é¤ì¤Æ·Ñ³¥Õ¥£¡¼¥ë¥É
(^
¤Ç»Ï¤Þ¤ë)¤ËÆþ¤ë»þ¤Î¤½¤ÎľÁ°¤Îʸ»ú¥»¥Ã¥È¡£
¥Ç¥Õ¥©¥ë¥È¤Ï ` \n-' ¤Ç¡¢
ʸ»úÎó¤Ï¥Û¥ï¥¤¥È¥¹¥Ú¡¼¥¹Ëô¤Ï¥Ï¥¤¥Õ¥ó¤Î¸å¤Çʬ¤±¤é¤ì¤ë¡£
³Ð¤¨Êý:
a "colon" in poetry is a part of a line.
$^D
: ¸½ºß¤Î¥Ç¥Ð¥Ã¥°¥Õ¥é¥°¤ÎÃÍ¡£
³Ð¤¨Êý:
-D
¥¹¥¤¥Ã¥Á¤ÎÃÍ¡£
$^F
: ¥·¥¹¥Æ¥à¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÎºÇÂçÃͤǡ¢Ä̾ï 2¡£
¥·¥¹¥Æ¥à¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï»Ò¥×¥í¥»¥¹¤ËÅϤµ¤ì¤ë¤¬¡¢
¤½¤ì¤è¤êÃͤ¬Â礤¤¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÅϤµ¤ì¤Ê¤¤¡£
open
¤ÎºÝ¤Ë¤Ï¡¢
¤¿¤È¤¨ open
¤¬¼ºÇÔ¤·¤Æ¤â¥·¥¹¥Æ¥à¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏÊݸ¤µ¤ì¤ë¡£
Ä̾ï¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï open
¤ò»î¤ß¤ëÁ°¤Ë close
¤µ¤ì¤ë¡£
³Ð¤¨Êý:
-D
¥¹¥¤¥Ã¥Á¤ÎÃÍ¡£
$^I
: ¥Õ¥¡¥¤¥ë¤ò¤½¤Î¾ì¤ÇÊѹ¹¤¹¤ë¾ì¹ç¤Î³ÈÄ¥»Ò¤ÎÃÍ¡£
¤½¤Î¾ì¤ÇÊѹ¹¤¹¤ë¤Î¤ò¶Ø»ß¤¹¤ë¤Ë¤Ï¡¢¤³¤ì¤ò undef ¤¹¤ë¡£
³Ð¤¨Êý:
-i
¥¹¥¤¥Ã¥Á¤ÎÃÍ¡£
$^L
: ²þ¥Ú¡¼¥¸¥³¡¼¥É¡£¥Ç¥Õ¥©¥ë¥È¤Ï \f
¡£
$^P
: ¥Ç¥Ð¥Ã¥¬¤¬¼«Ê¬¼«¿È¤ò¥Ç¥Ð¥Ã¥°¤·¤Ê¤¤¤¿¤á¤Ë¥¯¥ê¥¢¤¹¤ëÆâÉô¥Õ¥é¥°¡£
¤³¤ì¤ò¥¯¥ê¥¢¤¹¤ë¤³¤È¤Ç ¼«Ê¬¼«¿È¤ò¥Ç¥Ð¥Ã¥°¤¹¤ë¤³¤È¤òÉÔ²Äǽ¤Ë¤¹¤ë¤³¤È¤¬¹Í¤¨¤é¤ì¤ë¡£
$^T
: ¥¹¥¯¥ê¥×¥È¤Î¼Â¹Ô¤¬»Ï¤Þ¤Ã¤¿»þ¹ï(epoch ¤«¤é¤ÎÉÿô)¡£
¥Õ¥¡¥¤¥ë¥Æ¥¹¥È -M
,-A
,-C
¤ÇÊÖ¤ëÃͤϤ³¤ÎÃͤ˴ð¤Å¤¤¤Æ¤¤¤ë¡£
$^W
: ¸½ºß¤Î·Ù¹ð¥¹¥¤¥Ã¥Á¤ÎÃÍ¡£
³Ð¤¨Êý:
-w
¥¹¥¤¥Ã¥Á¤Ë´ØÏ¢¤·¤¿ÃÍ¡£
$^X
: Perl ¤½¤Î¤â¤Î¤¬µ¯Æ°¤µ¤ì¤¿ºÝ¤Î̾Á°¡£argv[0]
¤«¤éÆÀ¤ë¡£
$ARGV
: <>
¤«¤éÆɤ߹þ¤ó¤Ç¤¤¤ë»þ¡¢¥«¥ì¥ó¥È¥Õ¥¡¥¤¥ë̾¤¬Æþ¤Ã¤Æ¤¤¤ë¡£
@ARGV
: ¥¹¥¯¥ê¥×¥È¤ËÍ¿¤¨¤é¤ì¤¿¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¿ô¡£
$#ARGV
¤ÏÄÌ¾ï °ú¿ô¤Î¿ô - 1 ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤ËÃí°Õ¡£
¤Ê¤¼¤Ê¤é¡¢$ARGV[0]
¤ÏºÇ½é¤Î°ú¿ô¤Ç¤¢¤Ã¤Æ¡¢
¥³¥Þ¥ó¥É¤Î̾Á°¤Ç¤Ï¤Ê¤¤¤«¤é¤À¡£
¥³¥Þ¥ó¥É̾¤òÃΤë¤Ë¤Ï $0
¤ò¸«¤è¡£
See section @hbox{@hbox to 1.6em{@tt@$0@hfil} : ¼Â¹Ô¤·¤Æ¤¤¤ë perl ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾}.
@INC
: perl ¥¹¥¯¥ê¥×¥È¤òõ¤¹¾ì½ê¤Î¥ê¥¹¥È
do EXPR
¥³¥Þ¥ó¥É¤Þ¤¿¤Ï require
¥³¥Þ¥ó¥É¤Çɾ²Á¤µ¤ì¤ë¡£
ºÇ½é¤Ï ¥³¥Þ¥ó¥É¥¹¥¤¥Ã¥Á -I
¤Ç»ØÄꤷ¤¿°ú¿ô + ¥Ç¥Õ¥©¥ë¥È perl ¥é¥¤¥Ö¥é¥ê
(¿ʬ `/usr/local/lib/perl'¡¢
¼¡¤Ë `.' ¤¹¤Ê¤ï¤Á¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê )¤¬Æþ¤Ã¤Æ¤¤¤ë¡£
%INC
: ¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Î°ÌÃÖ
Ï¢ÁÛÇÛÎó INC
¤Ë¤Ï do
¤Þ¤¿¤Ï require
¤òÍѤ¤¤Æ
¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤¿¥Õ¥¡¥¤¥ë̾¤¬Æþ¤Ã¤Æ¤¤¤ë¡£
key ¤Ï»ØÄꤷ¤¿¥Õ¥¡¥¤¥ë̾¡¢
value ¤Ï¥Õ¥¡¥¤¥ë¤¬¼ÂºÝ¤Ë¸«¤Ä¤«¤Ã¤¿¾ì½ê¤Ç¤¢¤ë¡£
`require' ¥³¥Þ¥ó¥É¤Ï¤³¤ÎÇÛÎó¤òÍѤ¤¤Æ »ØÄꤷ¤¿¥Õ¥¡¥¤¥ë¤¬´û¤Ë¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤¿¤«¤É¤¦¤«¤ò·èÄꤹ¤ë¡£
%ENV
: ¸½ºß¤Î´Ä¶¡£
ENV
¤ÎÃͤòÊѹ¹¤¹¤ë¤È¡¢»Ò¥×¥í¥»¥¹¤Î´Ä¶¤âÊѤï¤ë¡£
%SIG
: ¤µ¤Þ¤¶¤Þ¤Ê signal ¤ËÂбþ¤¹¤ë¥Ï¥ó¥É¥é¤ò¥»¥Ã¥È¤¹¤ë¡£
(Îã)
sub handler { # 1st argument is signal name local($sig) = @_; print "Caught a SIG$sig--shutting down\n"; close(LOG); exit(0); } $SIG{'INT'} = 'handler'; $SIG{'QUIT'} = 'handler'; ... $SIG{'INT'} = 'DEFAULT'; # ¥Ç¥Õ¥©¥ë¥È¤Î¥¢¥¯¥·¥ç¥ó¤ËÌ᤹ $SIG{'QUIT'} = 'IGNORE'; # SIGQUIT ¤ò̵»ë¤¹¤ë
ÇÛÎó SIG
¤Ï perl ¥¹¥¯¥ê¥×¥È¤Ç¥»¥Ã¥È¤µ¤ì¤¿ signal ¤ËÂбþ¤¹¤ëÃͤ·¤«
´Þ¤Þ¤Ê¤¤¡£
perl ¤Ë¤ª¤¤¤Æ¤Ï¥Ñ¥Ã¥±¡¼¥¸´Ö¤ÇÊÑ¿ô¤¬´³¾Ä¤·¤¢¤ï¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¡¢
ÊÌ¡¹¤Î̾Á°¶õ´Ö¤òÍÑ°Õ¤·¤Æ¤¤¤ë¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢
perl ¥¹¥¯¥ê¥×¥È¤Ï main
¤È¤¤¤¦¥Ñ¥Ã¥±¡¼¥¸¤Ë¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë¡£
package
Àë¸À¤ò»È¤¦¤È¡¢Ì¾Á°¶õ´Ö¤òÊѤ¨¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¥Ñ¥Ã¥±¡¼¥¸Àë¸À¤Î¸ú¤¯ÈϰϤϡ¢Àë¸À¤«¤éÊĤ¸¤¿¥Ö¥í¥Ã¥¯¤ÎºÇ¸å¤Þ¤Ç¤Ç¤¢¤ë
(local()
Àë¸À»Ò¤ÈƱ¤¸)¡£
Ä̾¥Ñ¥Ã¥±¡¼¥¸Àë¸À¤Ï require
¤Ç¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤Î
ºÇ½é¤ÎÀë¸À¤È¤·¤Æ»È¤¦¡£
°ì²Õ½ê°Ê¾å¤Ç¥Ñ¥Ã¥±¡¼¥¸¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£ ¤½¤ì¤Ïñ¤Ë¥Ö¥í¥Ã¥¯¤Î»Ä¤ê¤ËÂФ·¤Æ¥³¥ó¥Ñ¥¤¥é¤¬»È¤¦ ¥·¥ó¥Ü¥ë¥Æ¡¼¥Ö¥ë¤¬ÊѤï¤ë¤À¤±¤Ç¤¢¤ë¡£
¼±Ê̻Ҥ˥ѥ屡¼¥¸Ì¾¤È '
(¥·¥ó¥°¥ë¥¯¥©¡¼¥È)¤ò¤Ä¤±¤ë¤³¤È¤Ç¡¢
¾¤Î¥Ñ¥Ã¥±¡¼¥¸¤ÎÊÑ¿ô¤ä¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò»²¾È¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¥Ñ¥Ã¥±¡¼¥¸Ì¾¤¬¤Ê¤±¤ì¤Ð¡¢main
¤¬»È¤ï¤ì¤ë¡£
¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤Ç»Ï¤Þ¤ë¼±Ê̻ҤΤߥѥ屡¼¥¸¤Î¥·¥ó¥Ü¥ë¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤µ¤ì¤ë¡£
¾¤Î¥·¥ó¥Ü¥ë¤Ï main
¥Ñ¥Ã¥±¡¼¥¸¤Ë³ÊǼ¤µ¤ì¤ë¡£
¤µ¤é¤Ë¡¢¼±ÊÌ»Ò STDIN
¡¢STDOUT
¡¢STDERR
¡¢ARGV
¡¢
ARGVOUT
¡¢ENV
¡¢INC
¡¢SIG
¤Ï
¤½¤ìËÜÍè¤ÎÌÜŪ°Ê³°¤Ë»È¤¦¾ì¹ç¤Ç¤â¥Ñ¥Ã¥±¡¼¥¸ main
¤Î¤Þ¤Þ¤Ç¤¢¤ë¡£
¤Þ¤¿¡¢`m'¡¢`s'¡¢`y' ¤È¤¤¤¦Ì¾Á°¤Î¥Ñ¥Ã¥±¡¼¥¸¤ò»È¤¦¤È¡¢ ¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò¤Ä¤±¤¿¼±Ê̻Ҥò»È¤¦¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£ ¤Ê¤¼¤Ê¤é¡¢¤½¤ì¤¾¤ì¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¡¢ÃÖ´¹¡¢ÊÑ´¹ ¤òɽ¤¹¤È²ò¼á¤µ¤ì¤ë¤«¤é¤Ç¤¢¤ë¡£
eval
¤µ¤ì¤ëʸ»úÎó¤Ï eval
¤ÈƱ¤¸¥Ñ¥Ã¥±¡¼¥¸¤Ë¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë¡£
(¤¿¤À¤·¡¢$SIG{}
¤Ø¤ÎÂåÆþ¤Ë¤ª¤¤¤Æ¤Ï¡¢
¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ï main
¥Ñ¥Ã¥±¡¼¥¸¤Ë¤¢¤ë¤È²¾Äꤵ¤ì¤ë¡£
¥Ñ¥Ã¥±¡¼¥¸Æâ¤Ë¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤òºî¤ê¤¿¤¤¾ì¹ç¤Ï
¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é̾¤Ë¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò¤Ä¤±¤ë¤³¤È¡£)
Îã¤È¤·¤Æ¤Ï¡¢perl ¥é¥¤¥Ö¥é¥ê¤Ë¤¢¤ë `perldb.pl' ¤¬¤¢¤ë¡£
¤³¤ì¤Ï¡¢¥Ç¥Ð¥Ã¥¬¤¬¥Ç¥Ð¥Ã¥°¤·¤è¤¦¤È¤¹¤ë¥¹¥¯¥ê¥×¥ÈÆâ¤ÎÊÑ¿ô¤ò´³¾Ä¤·¤Ê¤¤¤è¤¦¤Ë¡¢
ºÇ½é¤Ë DB
¥Ñ¥Ã¥±¡¼¥¸¤ËÆþ¤ë¡£
¤½¤·¤Æ¡¢¤¤¤í¤¤¤í¤Ê¾ì¹ç¤Ë¡¢
main
¥Ñ¥Ã¥±¡¼¥¸¤Îʸ̮¤Ç expression ¤òɾ²Á¤¹¤ë¤¿¤á¤Ë
°ì»þŪ¤Ë main
¥Ñ¥Ã¥±¡¼¥¸¤ËÀÚ¤êÊѤï¤ë¡£
¥Ñ¥Ã¥±¡¼¥¸¤Î¥·¥ó¥Ü¥ë¥Æ¡¼¥Ö¥ë¤Ï
¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ÎÁ°¤Ë `_' ¤ò¤Ä¤±¤¿Ì¾Á°¤ÎÏ¢ÁÛÇÛÎó¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¡£
Ï¢ÁÛÇÛÎó¤Î³Æ¥¨¥ó¥È¥ê¤ÎÃͤϡ¢
*name
µË¡¤ò»È¤¦ºÝ¤Ë»²¾È¤µ¤ì¤ëÃͤÈƱ¤¸¤Ç¤¢¤ë¡£
¼ÂºÝ¡¢¼¡¤ÎÎã¤ÏƱ¤¸¸ú²Ì¤¬¤¢¤ë(¤â¤Á¤í¤ó main
¥Ñ¥Ã¥±¡¼¥¸¤Ë¤ª¤¤¤Æ)¤¬¡¢
°ì¤ÄÌܤÎÊý¤¬¡¢¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¥·¥ó¥Ü¥ë¥Æ¡¼¥Ö¥ë¤òõ¤¹¤Î¤Ç¡¢¤è¤ê¸úΨ¤¬¤è¤¤¡£
local(*foo) = *bar; local($_main{'foo'}) = $_main{'bar'};
¤³¤ì¤ò»È¤Ã¤ÆÎ㤨¤Ð¥Ñ¥Ã¥±¡¼¥¸Æâ¤ÎÁ´ÊÑ¿ô¤ò½ÐÎϤ¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£ °Ê²¼¤Ë perl ¥é¥¤¥Ö¥é¥ê¤«¤é `dumpvar.pl' ¤ò¼¨¤¹¡£
package dumpvar; sub main'dumpvar { ($package) = @_; local(*stab) = eval("*_$package"); while (($key,$val) = each(%stab)) { { local(*entry) = $val; if (defined $entry) { print "\$$key = '$entry'\n"; } if (defined @entry) { print "\@$key = (\n"; foreach $num ($[ .. $#entry) { print " $num\t'",$entry[$num],"'\n"; } print ")\n"; } if ($key ne "_$package" && defined %entry) { print "\%$key = (\n"; foreach $key (sort keys(%entry)) { print " $key\t'",$entry{$key},"'\n"; } print ")\n"; } } } }
¤³¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤Ï dumpvar
¥Ñ¥Ã¥±¡¼¥¸Æâ¤Ë¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë¤¬¡¢
main
¥Ñ¥Ã¥±¡¼¥¸¤Ë¤ª¤¤¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó̾¤ò»ÈÍѲÄǽ¤È¤¹¤ë¤¿¤á¤Ë¡¢
¥µ¥Ö¥ë¡¼¥Á¥ó̾¤ÎÁ°¤Ë¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò¤Ä¤±¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³¤È¤ËÃí°Õ¡£
¥×¥í¥°¥é¥Þ¤Ë¤Ï³§¡¢ÅöÁ³¤Ê¤¬¤é¡¢Âκۤ˴ؤ·¤Æ¼«Ê¬¼«¿È¤Î¹¥¤ß¤¬¤¢¤ë¤¬¡¢ ¥×¥í¥°¥é¥à¤òÆɤ߰פ¯¤¹¤ë¤¿¤á¤Î°ìÈÌŪ¤Ê¥¬¥¤¥É¥é¥¤¥ó¤¬¤¤¤¯¤Ä¤«¤¢¤ë¡£
open(FOO,$foo) || die "Can't open $foo: $!";¤Ï¼¡¤è¤ê¤â¤è¤¤¡£
die "Can't open $foo: $!" unless open(FOO,$foo);¤Ê¤¼¤Ê¤é¡¢¸å¼Ô¤Ïʸ¤Î¥á¥¤¥ó¥Ý¥¤¥ó¥È¤ò½¤¾þ»Ò¤È¤·¤Æ±£¤·¤Æ¤¤¤ë¤«¤é¤Ç¤¢¤ë¡£ °ìÊý¡¢
print "Starting analysis\n" if $verbose;¤Ï¼¡¤è¤ê¤â¤è¤¤¡£
$verbose && print "Starting analysis\n";¤Ê¤¼¤Ê¤é¡¢ ¥á¥¤¥ó¥Ý¥¤¥ó¥È¤Ï¥æ¡¼¥¶¤¬
-v
¤ò¥¿¥¤¥×¤·¤¿¤«¤É¤¦¤«¤Ç¤Ï¤Ê¤¤¤«¤é¤À¡£
ƱÍͤˡ¢±é»»»Ò¤¬¥Ç¥Õ¥©¥ë¥È¤Î°ú¿ô¤ò²¾Äꤷ¤Æ¤¤¤ë¤«¤é¤È¤¤¤Ã¤Æ¡¢
¤½¤ì¤Ï¥Ç¥Õ¥©¥ë¥È¤òÍѤ¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤È¤¤¤¦¤³¤È¤Ç¤Ï¤Ê¤¤¡£
¥Ç¥Õ¥©¥ë¥È¤Ï¤Á¤ç¤Ã¤È¤·¤¿¥×¥í¥°¥é¥à¤ò½ñ¤¯
ÂÕ¤±¼Ô¤Î¥·¥¹¥Æ¥à¥×¥í¥°¥é¥Þ¤Î¤¿¤á¤Ë¤¢¤ë¡£
¥×¥í¥°¥é¥à¤òÆɤ߰פ¯¤·¤¿¤±¤ì¤Ð¡¢°ú¿ô¤ò½ñ¤¤¤¿Êý¤¬¤è¤¤¡£
¾å¤ÈƱ¤¸¤è¤¦¤Ê¤³¤È¤À¤¬¡¢
¤¢¤Á¤³¤Á¤Ç³ç¸Ì¤ò¾Êά¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤È¤¤¤¦¤³¤È¤Ï¼¡¤Î¤è¤¦¤Ë½ñ¤±¡¢
¤È¤¤¤¦¤³¤È¤Ç¤Ï¤Ê¤¤¡£
return print reverse sort num values array; return print(reverse(sort num (values(%array))));¤¢¤ä¤Õ¤ä¤Ê»þ¤Ï¡¢³ç¸Ì¤ò¤Ä¤±¤è¤¦¡£ ¾¯¤Ê¤¯¤È¤â¡¢Êª¹¥¤¤¬¡¢vi ¤Ç % ¥¡¼¤ò²¡¤¹¤«¤â¤·¤ì¤Ê¤¤¡£(?)
¤¢¤ä¤Õ¤ä¤Ç¤Ê¤¤»þ¤Ç¤â¡¢ ·¯¤Î¸å¤ò·Ñ¤¤¤Ç¥³¡¼¥É¤Î¥á¥ó¥Æ¥Ê¥ó¥¹¤ò¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¿Íʪ¤Î Àº¿ÀÊ¡Íø¤ò¹Í¤¨¤è¤¦¡£Èà¤Ï¤ª¤½¤é¤¯¸í¤Ã¤¿½ê¤Ë³ç¸Ì¤ò¤Ä¤±¤ë¤À¤í¤¦¡£When in doubt, parenthesize. At the very least it will let some poor schmuck bounce on the % key in vi.
last
Àë¸À»Ò¤òÍÑ°Õ¤·¤Æ¤¤¤ë¡£
¸«°×¤¯¤¹¤ë¤¿¤á¡¢¥¤¥ó¥Ç¥ó¥È¤ò¾¯¤·¾¯¤Ê¤¯¤·¤è¤¦¡£
line: for (;;) { statements; last line if $foo; next line if /^#/; statements; }
eval
¹½Â¤¤ÎÃæ¤Ç¤½¤ì¤¬¼ºÇÔ¤¹¤ë¤«¤É¤¦¤«¥Æ¥¹¥È¤»¤è¡£
¤¢¤ëµ¡Ç½¤¬
¤É¤Î¥Ð¡¼¥¸¥ç¥ó¡¢¤É¤Î¥Ñ¥Ã¥Á¥ì¥Ù¥ë¤Ç¥¤¥ó¥×¥ê¥á¥ó¥È¤µ¤ì¤¿¤«¤¬Ê¬¤«¤Ã¤Æ¤¤¤ë¤Ê¤é¡¢
$]
¤ò»È¤Ã¤Æ¤½¤Îµ¡Ç½¤¬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¤³¤È¤¬¤Ç¤¤ë¡£
perl ¤ò -d
¥ª¥×¥·¥ç¥ó¤ò¤Ä¤±¤Æµ¯Æ°¤¹¤ë¤È¡¢
¥Ç¥Ð¥Ã¥°¥â¥Ë¥¿¤Î¤â¤È¤Ç¥¹¥¯¥ê¥×¥È¤¬¼Â¹Ô¤µ¤ì¤ë¡£
¥Ç¥Ð¥Ã¥¬¤ÏºÇ½é¤Î¼Â¹Ô²Äǽʸ¤ÎÁ°¤Ç»ß¤Þ¤ê¡¢°Ê²¼¤Ë¼¨¤¹¥³¥Þ¥ó¥É¤òÆþÎϤ¹¤ë¤è¤¦Â¥¤¹¡£
main
¥Ñ¥Ã¥±¡¼¥¸¤Ç¤¢¤ë¡£
STDOUT
¤¬¥ê¥À¥¤¥ì¥¯¥È¤µ¤ì¤Æ¤¤¤Æ¤â¡¢
¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ëDB'OUT
¤Ï `/dev/tty' ¤Ë¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
¥Ç¥Ð¥Ã¥¬¤ò½¤Àµ¤·¤¿¤¤¾ì¹ç¤Ï¡¢
perl ¥é¥¤¥Ö¥é¥ê¤«¤é `perldb.pl' ¤ò¥³¥Ô¡¼¤·¡¢É¬Íפ˱þ¤¸¤Æ½¤Àµ¤¹¤ë¡£
(¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ë -I.
¤òÄɲ乤뤳¤È¤âɬÍפÀ¤í¤¦¡£)
`.perldb' ¤Ë½é´ü²½¥³¡¼¥É¤ò½ñ¤¯¤³¤È¤Ë¤è¤Ã¤Æ¥«¥¹¥¿¥Þ¥¤¥º¤¬¤Ç¤¤ë¡£ Î㤨¤Ð¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Æ¥¨¥¤¥ê¥¢¥¹¤òÄêµÁ¤Ç¤¤ë¡£
$DB'alias{'len'} = 's/^len(.*)/p length($1)/'; $DB'alias{'stop'} = 's/^stop (at|in)/b/'; $DB'alias{'.'} = 's/^\e./p "\e$DB\e'sub(\e$DB\e'line):\et",\e$DB\e'line[\e$DB\e'line]/';
perl ¤Ï°ÂÁ´¤Ê setuid¡¦setgid ¥¹¥¯¥ê¥×¥È¤ò °ÂÁ´¤Ë½ñ¤¯¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤ËÀ߷פµ¤ì¤Æ¤¤¤ë¡£ ¥·¥§¥ë¤Ï¡¢¥¹¥¯¥ê¥×¥È¤Î³Æ¹Ô¤òÊ£¿ô¤ÎÃÖ´¹¤Î¥Ñ¥¹¤òÄ̤·¤Æ¼Â¹Ô¤¹¤ë¤¬¡¢ perl¤Ï¤è¤êÅÁÅýŪ¤Êɾ²ÁË¡¤òÍѤ¤¤Æ¡¢ ±£¤ì¤¿"¤ï¤±¤Î¤ï¤«¤é¤Ê¤¤¤â¤Î"¤ò¾¯¤Ê¤¯¤·¤Æ¤¤¤ë¡£
¤µ¤é¤Ë¡¢perl ¤Ë¤Ï¤è¤ê¿¤¯¤Î¥Ó¥ë¥È¥¤¥ó´Ø¿ô¤¬¤¢¤ë¤Î¤Ç¡¢ ÌÜŪ¤ò㤹¤ë¤¿¤á¤Ë³°Éô¤Î(¤½¤·¤Æ¿ʬ¿®ÍѤǤ¤Ê¤¤)¥×¥í¥°¥é¥à¤ËÍê¤ëɬÍפ¬¾¯¤Ê¤¤¡£
¥Ñ¥Ã¥Á¤òÅö¤Æ¤Æ¤¤¤Ê¤¤ 4.2 ¤ä 4.3bsd ¥«¡¼¥Í¥ë¤Ç¤Ï¡¢ setuid ¥¹¥¯¥ê¥×¥È¤Ï´í¸±¤Ç¤¢¤ë¤È¸«¤Ê¤µ¤ì¤ë¤¬¡¢ ¤³¤Î¥«¡¼¥Í¥ë¤Îµ¡Ç½¤Ï»ÈÍÑÉԲĤˤ¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
¤½¤¦¤·¤Æ¤¢¤ë¾ì¹ç¡¢perl ¤Ï setuid¡¦setgid µ¡¹½¤ò¥¨¥ß¥å¥ì¡¼¥È¤·¡¢Æ±»þ¤Ë¡¢ ¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¥¹¥¯¥ê¥×¥È¤Ë¤Ä¤¤¤Æ¤¤¤ë setuid/gid ¥Ó¥Ã¥È¤Ï °ÕÌ£¤Î¤Ê¤¤¤â¤Î¤Ç¤¢¤ë¤³¤È¤òÃΤ餻¤ë¡£
¥«¡¼¥Í¥ë¤Îµ¡Ç½¤¬»ÈÍÑÉԲĤˤʤäƤ¤¤Ê¤¤¾ì¹ç¡¢ perl ¤Ï setuid ¥¹¥¯¥ê¥×¥È¤¬´í¸±¤Ç¤¢¤ë¤³¤È¤òÀ¼¹â¤ËÃí°Õ¤¹¤ë¡£ ¥«¡¼¥Í¥ë¤Î setuid ¥¹¥¯¥ê¥×¥Èµ¡Ç½¤ò»ÈÍÑÉԲĤˤ¹¤ë¤«¡¢ ¥¹¥¯¥ê¥×¥È¤Ë C ¤Î¥é¥Ã¥×¤ò¤«¤±¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
perl ¤¬ setuid ¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤¹¤ë»þ¤Ï¡¢ ÌÀ¤é¤«¤Ê¥È¥é¥Ã¥×¤Ë¤Ï¤Þ¤é¤Ê¤¤¤è¤¦¤ÊͽËɺö¤ò¼è¤ë¡£ (´ö¤Ä¤«¤ÎÅÀ¤Ç¡¢perl ¥¹¥¯¥ê¥×¥È¤ÏƱ¤¸ÆâÍƤΠC ¥×¥í¥°¥é¥à¤è¤ê¤â°ÂÁ´¤Ç¤¢¤ë¡£)
¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¿ô¡¢´Ä¶ÊÑ¿ô¡¢ÆþÎϤϤ¹¤Ù¤Æ"±ø¤ì¤Æ¤¤¤ë"¤È¸«¤Ê¤µ¤ì¡¢ ¥µ¥Ö¥·¥§¥ë¤òµ¯Æ°¤¹¤ë¥³¥Þ¥ó¥É¤ä¡¢ ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥ì¥¯¥È¥ê¡¦¥×¥í¥»¥¹¤òÊѹ¹¤¹¤ë¥³¥Þ¥ó¥É¤Ë¤Ï¡¢ ľÀÜŪ¤Ç¤¢¤ì´ÖÀÜŪ¤Ç¤¢¤ì¡¢»ÈÍѤ¬µö¤µ¤ì¤Ê¤¤¡£
²áµî¤Ë"±ø¤ì¤¿"Ãͤò»²¾È¤·¤¿ expression ¤Ç¥»¥Ã¥È¤µ¤ì¤¿ÊÑ¿ô¤â¤Þ¤¿ "±ø¤ì¤ë"("±ø¤ì¤¿"Ãͤ¬ÊÑ¿ô¤Ë±Æ¶Á¤òµÚ¤Ü¤¹¤³¤È¤¬ÏÀÍýŪ¤ËÉÔ²Äǽ¤Ç¤¢¤Ã¤Æ¤â)¡£
Î㤨¤Ð:
$foo = shift; # $foo ¤Ï±ø¤ì¤Æ¤¤¤ë $bar = $foo,'bar'; # $bar ¤â¤Þ¤¿±ø¤ì¤ë $xxx = <>; # ±ø¤ì¤Æ¤¤¤ë $path = $ENV{'PATH'}; # ±ø¤ì¤Æ¤¤¤ë¤¬¡¢²¼¤ò¸«¤è $abc = 'abc'; # ±ø¤ì¤Æ¤¤¤Ê¤¤ system "echo $foo"; # ´í¸± system "/bin/echo", $foo;# °ÂÁ´(sh ¤Ï»È¤ï¤Ê¤¤) system "echo $bar"; # ´í¸± system "echo $abc"; # PATH ¤¬¥»¥Ã¥È¤µ¤ì¤Ê¤¤¤«¤®¤ê´í¸± $ENV{'PATH'} = '/bin:/usr/bin'; $ENV{'IFS'} = " if $ENV{'IFS'} ne "; $path = $ENV{'PATH'}; # ±ø¤ì¤Æ¤¤¤Ê¤¤ system "echo $abc"; # º£Å٤ϰÂÁ´! open(FOO,"$foo"); # OK open(FOO,">$foo"); # OK ¤Ç¤Ï¤Ê¤¤ open(FOO,"echo $foo|"); # OK ¤Ç¤Ï¤Ê¤¤¤¬... open(FOO,"-|") || exec 'echo', $foo; # OK $zzz = `echo $foo`; # ´í¸±¡¢zzz ¤Ï±ø¤ì¤ë unlink $abc,$foo; # ´í¸± umask $foo; # ´í¸± exec "echo $foo"; # ´í¸± exec "echo", $foo; # °ÂÁ´(sh ¤Ï»È¤ï¤Ê¤¤) exec "sh", '-c', $foo; # °ÂÁ´¤È¤ß¤Ê¤µ¤ì¤ë¡¢¤¢¤¢
"±ø¤ì"¤ÏÁ´¥¹¥«¥é¡¼Ãͤȷë¹ç¤·¤Æ¤ª¤ê¡¢ ÇÛÎó¤Î´ö¤Ä¤«¤ÎÍ×ÁǤÏ"±ø¤ì¤Æ"¤¤¤Æ¤â¾¤ÎÍ×ÁǤÏÂç¾æÉס¢¤È¤¤¤¦¤³¤È¤â²Äǽ¤Ç¤¢¤ë¡£
²¿¤«´í¸±¤Ê¤³¤È¤ò¤·¤è¤¦¤È¤¹¤ë¤È¡¢
`Insecure dependency' ¤Þ¤¿¤Ï `Insecure PATH' ¤È¤¤¤¦¥á¥Ã¥»¡¼¥¸¤È¶¦¤Ë
Ã×̿Ū¤Ê¥¨¥é¡¼¤È¤Ê¤ë¡£
¤½¤ì¤Ç¤â´í¸±¤Ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤ä exec
¤ò½ñ¤¯¤³¤È¤Ï¤Ç¤¤ë¤¬¡¢
¤½¤ì¤Ï¾å¤ÎºÇ¸å¤ÎÎã¤Î¤è¤¦¤ÊÌÀ¤é¤«¤Ê¾ì¹ç¤Î¤ß¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¡£
¤Þ¤¿¡¢"±ø¤ì"µ¡¹½¤ò¥µ¥Ö¥Ñ¥¿¡¼¥ó¤ò»²¾È¤¹¤ë¤³¤È¤Ç²óÈò¤¹¤ë¤³¤È¤â¤Ç¤¤ë¡£
perl ¤Ï $1
¡¢$2
¤Ê¤É¤ò»È¤Ã¤Æ¥µ¥Ö¥¹¥È¥ê¥ó¥°¤ò»²¾È¤¹¤ë¾ì¹ç¤Ë¤Ï
¥Ñ¥¿¡¼¥ó¤ò½ñ¤¤¤¿¿Í¤¬²¿¤ò¤ä¤Ã¤Æ¤¤¤ë¤Î¤«¤òÃΤäƤ¤¤ë¤â¤Î¤À¤È²¾Äꤷ¤Æ¤¤¤ë¡£
$ARGV[0] =~ /^-P(\w+)$/; $printer = $1; # ±ø¤ì¤Æ¤¤¤Ê¤¤
\w+
¤Ï¥·¥§¥ë¤Î¥á¥¿¥¥ã¥é¥¯¥¿¤Ë¥Þ¥Ã¥Á¤·¤Ê¤¤¤Î¤Ç¡¢
¤³¤ì¤Ï¤«¤Ê¤ê°ÂÁ´¤Ç¤¢¤ë¡£
.+
¤ò»È¤Ã¤Æ¤¤¤¿¤é´í¸±¤Ç¤¢¤Ã¤¿¤À¤í¤¦¤¬¡¢perl ¤Ï¤½¤ì¤ò¥Á¥§¥Ã¥¯¤·¤Ê¤¤¤Î¤Ç¡¢
¥Ñ¥¿¡¼¥ó¤Ë¤ÏÃí°Õ¤¹¤ë¤Ù¤¤Ç¤¢¤ë¡£
¤³¤ì¤Ï¡¢¥Õ¥¡¥¤¥ëÁàºî¤ò¹Ô¤¦¾ì¹ç¤Ë¥æ¡¼¥¶¤¬Í¿¤¨¤ë¥Õ¥¡¥¤¥ë̾¤ò"±ø¤µ¤Ê¤¤"¤¿¤á¤Î
Í£°ì¤Îµ¡¹½¤Ç¤¢¤ë¡£
($>
¤ò $<
¤ÈƱ¤¸¤Ë¤·¤Ê¤¤¤«¤®¤ê¡£)
"±ø¤ì¤¿"Ãͤòµ¤¤Ë¤«¤±¤Ê¤¤Â¾¤ÎÁàºî¤Ë¤ª¤¤¤Æ¤â¥È¥é¥Ö¥ë¤òµ¯¤³¤·ÆÀ¤ë¡£
¥æ¡¼¥¶¤¬Í¿¤¨¤ë¥Õ¥¡¥¤¥ë̾¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¥Æ¥¹¥È¤ò¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢
¤è¤¯¹Í¤¨¤ë¤è¤¦¤Ë¡£
²Äǽ¤Ê¤é¤Ð¡¢ $> = $<
¤È¤·¤¿¸å¤Ç open
¤Ê¤É¤ò¹Ô¤Ã¤¿Êý¤¬¤¤¤¤¡£
perl ¤Ï"±ø¤ì¤¿"̾Á°¤Î¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ß¤Î¤¿¤á¤Ë open
¤¹¤ë¤³¤È¤òµö¤¹¡£
¤·¤¿¤¬¤Ã¤Æ¡¢½ÐÎϤ¹¤ëÆâÍƤˤÏÃí°Õ¤¹¤ë¤³¤È¡£
$>
¤Ë¤Ä¤¤¤Æ¤Ï @xref{$right,,@tt{$>}}, ¤ª¤è¤Ó
$<
¤Ë¤Ä¤¤¤Æ¤Ï @xref{$left,,@tt{$<}}.
"±ø¤ì"µ¡¹½¤ÏÇϼ¯¤²¤¿´Ö°ã¤¤¤òËɤ°¤¿¤á¤Ëºî¤Ã¤¿¤â¤Î¤Ç¡¢ ²¿¤â¹Í¤¨¤Ê¤¯¤Æ¤â¤è¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
chdir
¤Ë°ú¿ô¤¬¤Ê¤¤»þ»ÈÍѤµ¤ì¤ë¡£
chdir
¤Ë°ú¿ô¤¬¤Ê¤¯¡¢¤«¤Ä HOME ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤»þ»ÈÍѤµ¤ì¤ë¡£
-S
¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¥¹¥¯¥ê¥×¥È¤òõ¤¹ºÝ¤Ë»ÈÍѤ¹¤ë¡£require 'perldb.pl'¤ò»ÈÍѤ¹¤ë¡£
¼Â¹Ô»þ¤Ë¥¹¥¯¥ê¥×¥È¤ª¤è¤Ó»Ò¥×¥í¥»¥¹¤«¤é´Ä¶ÊÑ¿ô¤ò»ÈÍѲÄǽ¤Ë¤¹¤ë¤³¤È¤ò½ü¤¤¤Æ¡¢ perl ¤Ï¤³¤ì¤é°Ê³°¤Î´Ä¶ÊÑ¿ô¤òÍѤ¤¤Ê¤¤¡£ ¤·¤«¤·¡¢setuid ¤µ¤ì¤¿¥¹¥¯¥ê¥×¥È¤Ç¤Ï¡¢ ÍÑ¿´¤·¤Æ²¿¤è¤ê¤âºÇ½é¤Ëɬ¤º°Ê²¼¤Î¹Ô¤ò¼Â¹Ô¤¹¤ë¤Î¤¬¤è¤¤¤À¤í¤¦¡£ ¤³¤ì¤Ï¥æ¡¼¥¶¤Ë±³¤ò¤Ä¤«¤»¤Ê¤¤¤¿¤á¤Ç¤¢¤ë(just to keep people honest)¡£
$ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need $ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne "; $ENV{'IFS'} = " if $ENV{'IFS'} ne ";
Larry Wall <lwall@netlabs.com>
MS-DOS ¥µ¥Ý¡¼¥È¤Ï Diomidis Spinellis <dds@cc.ic.ac.uk>
-e
¥ª¥×¥·¥ç¥ó¤ò¤Ä¤±¤¿»þ¤Ë»ÈÍѤ¹¤ë¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë
/tmp/perl-eXXXXXX
¥³¥ó¥Ñ¥¤¥ë¥¨¥é¡¼¤Ï¥¨¥é¡¼¤Îµ¯¤³¤Ã¤¿¹ÔÈÖ¹æ¤Ë²Ã¤¨¤Æ¡¢
¼¡¤Ë²òÀϤµ¤ì¤ë¤Ï¤º¤À¤Ã¤¿¥È¡¼¥¯¥ó¤Þ¤¿¤Ï¥È¡¼¥¯¥ó¤Î¼ïÎà¤ò¶µ¤¨¤Æ¤¯¤ì¤ë¡£
(-e
¥ª¥×¥·¥ç¥ó¤òÄ̤·¤Æ perl ¤ËÅϤµ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¾ì¹ç¤Ï¡¢
³Æ¡¹¤Î -e
¤¬ 1 ¹Ô¤È¿ô¤¨¤é¤ì¤ë¡£)
¤µ¤é¤Ë Setuid ¥¹¥¯¥ê¥×¥È¤Î¾ì¹ç¤Ë¤Ï¡¢ `Insecure dependency' ¤Î¤è¤¦¤Ê¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òµ¯¤³¤¹¾ì¹ç¤¬¤¢¤ë¡£ Setuid ¥¹¥¯¥ê¥×¥È¤Î¹à¤ò»²¾È¡£ See section Setuid ¥¹¥¯¥ê¥×¥È.
if
¤ä while
¤ò»È¤¦»þ¤Ë¤Ï { }
¤¬É¬ÍפǤ¢¤ë¡£
$
¤« @
¤Ç»Ï¤Þ¤ë¡£
$[
¤ò¥»¥Ã¥È¤·¤Ê¤¤¤«¤®¤êÇÛÎ󟤨»ú¤Ï 0 ¤«¤é»Ï¤Þ¤ë¡£
substr()
¤ä index()
¤Ë¤ª¤±¤ëʸ»ú°ÌÃÖ¤âƱÍͤǤ¢¤ë¡£
split
¤·¤Æ¤¯¤ì¤Ê¤¤¡£
¼«Ê¬¤Ç split
¤·¤ÆÇÛÎó¤Ë³ÊǼ¤¹¤ëɬÍפ¬¤¢¤ë¡£
¤½¤·¤Æ¡¢split
´Ø¿ô¤Ï°Û¤Ê¤ë°ú¿ô¤ò¤È¤ë¡£
$0
¤Ç¤Ï¤Ê¤¯Ä̾ï $_
¤ËÆþ¤Ã¤Æ¤¤¤ë¡£
ÉáÄÌ¡¢²þ¹Ô¤Ï¼è¤ê½ü¤«¤ì¤Æ¤¤¤Ê¤¤¡£
($0
¤Ï¼Â¹Ô¤·¤Æ¤¤¤ë¥×¥í¥°¥é¥à¤Î̾Á°¤Ç¤¢¤ë¡£)
$¿ô»ú
¤ÏÆþÎϹԤΥե£¡¼¥ë¥É¤ò»²¾È¤·¤Ê¤¤ ---
ºÇ¸å¤Î¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤Ç¥Þ¥Ã¥Á¤·¤¿³Æʸ»úÎó¤ò»²¾È¤¹¤ë¡£
$,
¡¢$\
¤ò¥»¥Ã¥È¤·¤Ê¤¤¤«¤®¤ê¡¢
print
¤Ï¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿¡¢¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤ò½ÐÎϤ·¤Ê¤¤¡£
..
¤Ç¤¢¤ê¡¢¥³¥ó¥Þ¤Ç¤Ï¤Ê¤¤¡£
(¥³¥ó¥Þ¤Ï C ¤ÈƱ¤¸¤è¤¦¤ËƯ¤¯¡£)
=~
¤Ç¤¢¤ê¡¢~
¤Ç¤Ï¤Ê¤¤¡£
(~
¤Ï¡¢C ¤ÈƱ¤¸¤¯¡¢Êä¿ô¤òɽ¤¹¡£)
**
¤Ç¤¢¤ê¡¢^
¤Ç¤Ï¤Ê¤¤¡£
(^
¤Ï¡¢C ¤ÈƱ¤¸¤¯¡¢XOR ±é»»»Ò¤Ç¤¢¤ë¡£)
.
¤Ç¤¢¤ê¡¢¥Ì¥ëʸ»úÎó¤Ç¤Ï¤Ê¤¤¡£
(¥Ì¥ëʸ»úÎó¤ò»È¤Ã¤¿¤Ê¤é¡¢/pat/ /pat/
¤¬²òÀÏÉÔǽ¤Ë¤Ê¤ë¤À¤í¤¦¡£
¤Ê¤¼¤Ê¤é¡¢3 ¤Ä¤á¤Î¥¹¥é¥Ã¥·¥å¤Ï½ü»»±é»»»Ò¤È²ò¼á¤µ¤ì¤ë¤«¤é¤Ç¤¢¤ë¡£---
¥È¡¼¥¯¥ó²ò¼á¤Ï¼ÂºÝ¤Î½ê¡¢
/
¤ä ?
¤ä <
¤È¤¤¤Ã¤¿±é»»»Ò¤Ë¤Ä¤¤¤Æ¤Ï
¾¯¤·¥³¥ó¥Æ¥¥¹¥È¤ËÉÒ´¶¤Ç¤¢¤ë¡£
¤½¤·¤Æ¡¢¼Â¤Ï¡¢ .
¤½¤ì¼«ÂΤϿô»ú¤ÎºÇ½é¤Ë¤â¤Ê¤ê¤¦¤ë¤Î¤Ç¤¢¤ë¡£)
next
¡¢exit
¡¢continue
¤ÎƯ¤¤¬°ã¤¦¡£
awk perl ARGC $#ARGV ARGV[0] $0 FILENAME $ARGV FNR $. - something FS (²¿¤Ç¤â¤è¤¤) NF $#Fld, or some such NR $. OFMT $# OFS $, ORS $\ RLENGTH length($&) RS $/ RSTART length($`) SUBSEP $;
if
¤ä while
¤ò»È¤¦»þ¤Ë¤Ï { }
¤¬É¬ÍפǤ¢¤ë¡£
else if
¤ÎÂå¤ï¤ê¤Ë elsif
¤ò»È¤¦¡£
break
¡¢continue
¤Ï¤½¤ì¤¾¤ì last
¡¢next
¤È¤Ê¤ë¡£
switch
ʸ¤Ï¤Ê¤¤¡£
$
¤« @
¤Ç»Ï¤Þ¤ë¡£
*
¤ò¥¤¥ó¥×¥ê¥á¥ó¥È¤·¤Æ¤¤¤Ê¤¤¡£
#
¤Ç»Ï¤Þ¤ë¡£ /*
¤Ç¤Ï¤Ê¤¤¡£
ARGV
¤ÏÂçʸ»ú¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
link
¡¢unlink
¡¢rename
¤Ê¤É¤Î"¥·¥¹¥Æ¥à"¥³¡¼¥ë¤Ï
À®¸ù¤¹¤ì¤ÐÈó 0 ¤òÊÖ¤¹¡£0 ¤Ç¤Ï¤Ê¤¤¡£
\
¤Ç¤Ï¤Ê¤¯ $
¤ò»È¤¦¡£
(
¡¢)
¡¢|
¤ÎÁ°¤Ë¤Ï
¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤ò¤Ä¤±¤Ê¤¤¡£
..
¤Ç¤¢¤ê¡¢¥³¥ó¥Þ¤Ç¤Ï¤Ê¤¤¡£
(¥³¥ó¥Þ¤Ï C ¤ÈƱ¤¸¤è¤¦¤ËƯ¤¯¡£)"
±é»»»Ò¤Ë¤ª¤¤¤Æ¤Ï¡¢
¥³¥Þ¥ó¥É¤ò "
¤Ç³ç¤é¤Ê¤±¤ì¤ÐÊÑ¿ôÃÖ´¹¤¬¹Ô¤ï¤ì¤ë¡£
"
±é»»»Ò¤Ï¡¢`csh' ¤È°Û¤Ê¤ê¡¢ÊÖ¤êÃͤò¤½¤Î¤Þ¤ÞÊÖ¤¹¡£
""
¡¢"
¡¢<>
¡¢¸¡º÷¥Ñ¥¿¡¼¥ó¤Ê¤É¡¢
ÆÃÄê¤Î¹½Â¤¤Ë¤Ä¤¤¤ÆÃÖ´¹¤ò¹Ô¤¦¡£
@ARGV
¤òÄ̤·¤ÆÍøÍѲÄǽ¤Ç¤¢¤ë¡£
$1
¡¢$2
¤Ê¤É¤Ç¤Ï¤Ê¤¤¡£
Perl ¤ÎËÜ¡¢Programming Perl ¤Ç¤Ï ¼¡¤Î¹àÌܤò¾Êά¤¢¤ë¤¤¤ÏÆþ¤ì»¤Ê¤Ã¤Æ¤¤¤ë¡£
eval "/usr/bin/perl¤Ï°Ê²¼¤¬Àµ¤·¤¤¡£
eval "exec /usr/bin/perl
undef $/; $checksum = unpack("%32C*",<>) % 32767;
alarm
¤È sleep
¤Îµ½Ò¤¬
¥·¥°¥Ê¥ë SIGALARM
¤Ë¸ÀµÚ¤·¤Æ¤¤¤ë¤¬¡¢
¤³¤ì¤é¤Ï SIGALRM
¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£$/
¤Ë½é´üÃͤò¥»¥Ã¥È¤¹¤ë -0
¥¹¥¤¥Ã¥Á¤¬ Perl ¤ËÄɲ䵤줿¡£-l
¥¹¥¤¥Ã¥Á¤¬¼«Æ°Åª¤Ê¹ÔËö½èÍý¤ò¹Ô¤¦¤è¤¦¤Ë¤Ê¤Ã¤¿¡£
qx//
¹½Â¤¤¬ "
¤ÈƱµÁ¤Ë¤Ê¤Ã¤¿¡£
$0
¤ËÂåÆþ¤ò¹Ô¤¦¤³¤È¤¬²Äǽ¤Ë¤Ê¤Ã¤¿¡£@###.##
¤¬¶öÁ³¾Êά¤µ¤ì¤¿¡£
s///ee
¤¬É¾²Á¤òÊ£¿ô²ó¹Ô¤¦¤³¤È¤¬¤ï¤«¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
¤³¤ì¤Ï»ÅÍͤȲò¼á¤¹¤ë¤Ù¤¤Ç¤¢¤ë¡£(LIST) x $count
¤¬ÇÛÎó¤Î·«¤êÊÖ¤·¤ò¹Ô¤¦¤è¤¦¤Ë¤Ê¤Ã¤¿¡£
""
Æâ¤Ë¤ª¤¤¤Æ¡¢¥¨¥¹¥±¡¼¥×¤¬Äɲ䵤줿:\e
,\a
,\x1b
,\c[
,\l
,\L
,\u
,\U
,\E
.$/
¤ÏÊ£¿ôʸ»ú¤Î¥Ç¥ê¥ß¥Ã¥¿¤È¤·¤Æ¥»¥Ã¥È¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£g
½¤¾þ»Ò¤¬¤â¤¦¤±¤é¤ì¤¿¡£
¤³¤ì¤Ë¤è¤ê°ì¤Ä¤Îʸ»úÎó¤ËÂФ·Ê£¿ô¤Î¥Þ¥Ã¥Á¸¡º÷¤ò·«¤êÊÖ¤¹¤³¤È¤¬²Äǽ¤Ë¤Ê¤Ã¤¿¡£eval {}
¤È sort {}
¹½Â¤¤¬¥Ð¡¼¥¸¥ç¥ó 4.011 ¤ÇÄɲ䵤줿¡£perl ¤Ï·¿¥¥ã¥¹¥Æ¥£¥ó¥°¡¢atof()¡¢sprintf() ¤Ê¤É¤Î ¤µ¤Þ¤¶¤Þ¤ÊÁàºî¤Ë¤Ä¤¤¤Æ¡¢¤¢¤Ê¤¿¤Î¥Þ¥·¥ó¤ÎÄêµÁ¤ò»È¤Ã¤Æ¤¤¤ë¡£
stdio ¤¬¤¢¤ë¥¹¥È¥ê¡¼¥à¤Î read ¤È write ¤Î´Ö¤Ë¡¢
seek ¤Þ¤¿¤Ï eof ¤òɬÍפȤ·¤Æ¤¤¤ë¤Ê¤é perl ¤â¤½¤¦¤Ê¤ë¡£
(¤³¤ì¤Ï sysread()
¤ª¤è¤Ó syswrite()
¤Ë¤Ï¤¢¤Æ¤Ï¤Þ¤é¤Ê¤¤¡£)
¤É¤Î¥Ç¡¼¥¿¥¿¥¤¥×¤Ë¤â·è¤Þ¤Ã¤¿¥µ¥¤¥º¤Î¾å¸Â¤Ï¤Ê¤¤¤¬(¥á¥â¥ê¥µ¥¤¥º¤ÏÊÌ)¡¢ ¤½¤ì¤Ç¤â¤¤¤¯¤Ä¤«¤Î¸Â³¦¤¬¤¢¤ë¡£
-S
¤ò»È¤¦¾ì¹ç¡¢
PATH
¤Î¤É¤ÎÍ×ÁǤâ 255 ʸ»ú¤òĶ¤¨¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
perl ¤Ï¼ÂºÝ¤Î½ê¤Ï¡¢`Pathologically Eclectic Rubbish Lister' (ÉÂÍý³ØŪÀÞÃï¼çµÁ¤¯¤º¥ê¥¹¥¿¡¼)¤Îά¤Ç¤¢¤ë¤¬¡¢ »ä¤¬¤½¤¦¸À¤Ã¤¿¤È¤¤¤¦¤³¤È¤Ï¤À¤ì¤Ë¤â¸À¤ï¤Ê¤¤¤Ç¤Û¤·¤¤¡£
This document was generated on 10 September 1996 using the texi2html translator version 1.50.