Regular Expression À» »ç¿ëÇÑ Substitution

Perl ÀÇ substitution À» »ç¿ëÇÏ¿© ÅؽºÆ® ÆÄÀÏÀÇ ÀϺκÐÀ» HTML tag ·Î º¯È¯ÇØ ÁÖ´Â ÇÁ·Î±×·¥À» ¸¸µé¾ú´Ù. ¿ø·¡ÀÇ ÅؽºÆ® ÆÄÀÏ¿¡´Â xxx(yyy) ÇüÅÂÀÇ ºÎºÐÀÌ ¸¹ÀÌ µé¾î À־ »ö±òÀ» ³Ö´Âµ¥ ÁÁÀº ¿¹¹®ÀÌ µÇ¾ú´Ù. ¾Æ·¡ ¼Ò½º¸¦ Âü°íÇϱ⠹ٶõ´Ù.

¿ë¹®°´ÀÜ ( º¯È¯µÈ °á°ú )

Á¦ 1 È­ Áß¿ø(ñéê«)ÀÇ Ç÷dz(úìù¦)

Á¦ 2 È­ ´ëÇ÷°Ì(ÓÞúì̤)ÀÇ ¼­°î(ßíÍØ)

Á¦ 3 È­ ãæ éÌÚ¦ËÔíÑ (POG Version)

Source Code
#!/usr/bin/perl

$filename = '/home/scgyong/public_html/misc/yongmun/yongmun.txt';

main();

# end of execution

sub main {

    setReplace();

    print <<EOM;
Content-type: text/html

<HTML>
<BODY BACKGROUND="yh.gif">
EOM

    open(FILE, $filename) or die $!;
    while (<FILE>) {
        my($qopen, $qclose);

        $qopen = $rep11 if (m/^\s*"/);
        $qclose = $rep12 if (m/"\s*$/);

        s/([^-\s"]+?)\(([^-\s"]+?)\)/$rep21\1$rep22\2$rep23/g;
        s/^\s*\n/<P>\n/;
        s/^-(.*)\n/\1<BR>\n/;
        s/\cM//;
        print $qopen; print; print $qclose;
    }
    close(FILE);

    print <<EOM;
</BODY>
</HTML>

EOM

}

sub setReplace {

    $rep11 = <<EOM;
 <UL>
  <FONT COLOR="#007777">
EOM

    $rep12 = <<EOM;
  </FONT>
 </UL>
EOM

    $rep21 = qq|<FONT COLOR="#0000FF">|;
    $rep22 = qq|</FONT>(<FONT COLOR="#007700">|;
    $rep23 = qq|</FONT>)|;

}

# end of script