ファイル名: ./j/p_match.cgi

#!/usr/local/bin/perl


# -----------------------------------------------------------------------------
# パターンマッチングとデータ変換 (ファイル名: p_match.cgi )
# -----------------------------------------------------------------------------

$Title = 'パターンマッチングとデータ変換';

# ----------------------HTML & Perl ------------------------------
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>$Title</TITLE>\n";
print "</HEAD>\n";
print "<BODY bgcolor=#000000 text=#ffff99>\n";

# ----------------------------------------------------------
print "<B>■1. 「+」を半角スペースにもどす</B><BR><BR>";
print "フォームで半角スペースを送ると「+」になる<BR><BR>";

    $name = "John+Lennon";

print "\$name = $name<BR><BR>";

    $name =~ tr/\+/ /;

print "\$name =~ tr/+/ /<BR><BR>";
print "\$name = $name<BR><BR>";
print "<BR><BR>";


# ----------------------------------------------------------
print "<B>■2. 「%** %**」を漢字にもどす</B><BR><BR>";
print "フォームで漢字(全角)を送ると「%**%**」になる<BR><BR>";

    $comment = "%8A%BF%8E%9A%82%CD%82%B1%82%A4%82%C8%82%E9";

print "\$comment = $comment<BR><BR>";

    $comment =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

print "\$comment =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(\"C\", hex(\$1))/eg<BR><BR>";
print "\$comment = $comment<BR><BR>";
print "<BR><BR>";


# ----------------------------------------------------------
print "<B>■3. HTMLタグを使えなくする</B><BR><BR>";

    $URL = "<A href=\"http://www.asahi-net.or.jp/~JU8Y-HSTN/index.htm\">Home Page</A> ";


# print "\$URL = \<A href=\"http://www.asahi-net.or.jp/~JU8Y-HSTN/index.htm\"\>Home Page\</A\> ";
print "\$URL = $URL<BR><BR>";
    
    $URL =~ s/</</g;
    $URL =~ s/>/>/g;

print "\$URL =~ s/</&lt;/g;<BR><BR>";
print "\$URL =~ s/>/\&gt;/g;<BR><BR>";
print "\$URL = $URL<BR><BR>";

print "<BR><BR>";


# ----------------------------------------------------------
print "<B>■4. 「改行」と「,」を削除</B><BR><BR>";

print "\$value =~ s/\\n//g;<BR><BR>";
print "\$value =~ s/\\,//g;<BR><BR>";

print "<BR><BR>";


# ----------------------------------------------------------
print "<B>[補足] --- 16進数 ---</B> <BR><BR>";


print"<BR><BR>";

  print "\hex('0x0D') = ", hex('0x0D');

print"<BR><BR>";

  print "\sprintf(\"%02X\", 13) = ",sprintf("%02X", 13);

print"<BR><BR>";

  print "\pack(\"CCCC\",0x8A,0xBF,0x8E,0x9A) = ",pack("CCCC",0x8A,0xBF,0x8E,0x9A);

print"<BR><BR><BR><BR>";

print "●16進数で使われる文字 (0_255)";
print"<BR><BR>";

foreach $KAZU (0..255) {
  print sprintf("%02x", $KAZU)," ";
if (++$i == "16"){
print "<BR><BR>";
$i=0;
}
}

print"<BR><BR>";

foreach $KAZU (0..255) {
  print sprintf("%02X", $KAZU)," ";
if (++$i == "16"){
print "<BR><BR>";
$i=0;
}
}

print"<BR><BR><BR><BR>";
print "●アスキーコード (32_255)";
print"<BR><BR>";
foreach $KAZU (32..255) {
  print "&#",$KAZU,"; ";
if (++$i == "16"){
print "<BR><BR>";
$i=0;
}
}


print "</BODY>\n";
print "</HTML>\n";





exit;