· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
pung96

ÀÛ¼ºÁßÀÎ ¹®¼­

Âü°í ÆäÀÌÁö

3. MEMO

4. Perl Pattern Matching

4.1. ¿ä¾à

  • Pattern
    . ÀÓÀÇÀÇ ±ÛÀÚ¿¡ ¸ÅÄ¡(\nÀ» ¸ÅÄ¡ÇÏ·Å /s»ç¿ë)
    (...) ±×·ìÀ» ¹­´Â´Ù
    ^$ ¹®ÀåÀÇ ½ÃÀÛ(^)°ú ³¡($). cf) /m
    [...] []¾È¿¡ ¿­°ÅµÈ ±ÛÀÚÁß ÇѱÛÀÚ cf)¹Ý´ë´Â [^]
    (..|..|..) |·Î ±¸ºÐµÈ ÆÐÅÏÁß Çϳª¿¡ ¸ÅÄ¡
    (?#TEXT)
    (?:REGEXP)
    (?=REGEXP)
    (?!REGEXP)
    (MODIFIER)

  • Quantifier
    +
    ?
    *
    {n,m}
    +? *?

    \w \W Word(\w) == 0-9a-zA-Z_. \W==^\w
    \s \S
    \d \D
    \A
    \b
    \G
    \n \r \f \t

  • Back reference
    \1 \2 .. \9

  • Special Var
    $1..$9
    $+
    $&
    $'
    $`
  • ÆÐÅϸÅĪ º¯°æÀÚ
    /i ´ë¼Ò¹®ÀÚ ¹«½Ã
    /x °ø¹éÀ» ¹«½ÃÇÏ°í comment(#)À» Çã¿ëÇÑ´Ù
    /g Àü¿ª ¸ÅÄ¡,ġȯ(°¡´ÉÇÑÇÑ ÃÖ´ëÇÑ Àû¿ëµÈ´Ù)
    /gc ¸ÅÄ¡¿¡ ½ÇÆÐÇßÀ»¶§ °Ë»ö ÁöÁ¡À» ÃʱâÈ­ ÇÏÁö ¾Ê´Â´Ù
    /s .¿¡ \nÀÌ ¸ÅÄ¡µÇµµ·ÏÇÏ°í $*´Â ¹«½ÃÇÑ´Ù
    /m ^¿Í $°¡ \n´ÙÀ½¿¡ ¸ÅÄ¡µÇµµ·Ï ÇÑ´Ù
    /o ÆÐÅÏÀ» Çѹø¸¸ ÄÄÆÄÀÏ
    /e s///¿À¸¥ÂÊÀ» eval
    /ee s/// ¿À¸¥ÂÊÀ» evaló¸®ÇÏ°í °á°ú¸¦ Çѹø´õ eval

4.2. ÆÐÅϸÅĪ º¯°æÀÚ

  • /i : ´ë¼Ò¹®ÀÚ¸¦ ±¸º°ÇÏÁö ¾Ê°í ¸ÅĪÀ» ÇÑ´Ù. use locale °¡ ¼³Á¤µÇ¾î ÀÖÀ¸¸é locale¼³Á¤À» ¹Ý¿µÇÑ´Ù. ¼Óµµ°¡ ´Ù¼Ò ´À·ÁÁø´Ù´Â ´ÜÁ¡ÀÌ ÀÖ´Ù
  • /g
    • s///g ¸ðµç ¸ÅÄ¡¿¡ ´ëÇØ Ä¡È¯ ÀÛ¾÷À» ¼öÇà.
    • m//g : ¹ß»ýÇÏ´Â ¸ðµç ¸ÅÄ¡¸¦ ã´Â´Ù ´Ü °ãÄ¡Áö ¾Ê´Â ¸ÅÄ¡¸¸À» ã¾Æ³»¹Ç·Î °ãÄ¡´Â ¸ðµç ¸ÅÄ¡¸¦ ã¾Æ³»·Á¸é (?=)À» »ç¿ëÇؾßÇÑ´Ù.
      @array = m/(\d\d\d)/g;
      @array = m/(?=(\d\d\d))/g;
      

5. Perl Function

@sorted = sort @list;
@sorted = sort { $a <=> $b } @list; # ¼ýÀÚ Á¤·Ä
@sorted = sort { $a cmp $b } @list; # ¹®ÀÚ¿­ Á¤·Ä
@sorted = sort { EXPR } @list;
  • =$a<=>$b= : =<=>= ´Â ¼ýÀÚºñ±³¿¬»êÀÚ. ¿À¸§Â÷¼ø Á¤·ÄÀº =$b<=>$a=
  • $a ¿Í $b´Â Àü¿ªÆÐÅ°Áö º¯¼ö·Î ÇÒ´çµÈ´Ù.
  • ¼­ºê·çƾÀ» ÀÌ¿ëÇÑ Á¤·Ä
@sorted = sort { compare() } @list;

ID
Password
Join
Standing on head makes smile of frown, but rest of face also upside down.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-02-18 16:39:03
Processing time 0.0066 sec