<?xml version='1.0' encoding='utf-8'?>
<pod xmlns="http://axkit.org/ns/2000/pod2xml">
<head>
	<title>perlfaq9 - Networking ($Revision: 8539 $)</title>
</head>
<sect1>
<title>perlfaq9 - Networking ($Revision: 8539 $)</title>
<para>
perlfaq9 - ネットワーク ($Revision: 8539 $)
</para>
</sect1>
<sect1>
<title>DESCRIPTION</title>
<para>
This section deals with questions related to networking, the internet,
and a few on the web.
</para>
<para>
このセクションでは、ネットワーク、インターネット、web に関する
質問を扱っています。
</para>
<sect2>
<title>What is the correct form of response from a CGI script?</title>
<para>
(CGI スクリプトからの返答の正しい形は?)
</para>
<para>
(Alan Flavell &lt;flavell+www@a5.ph.gla.ac.uk&gt; answers...)
</para>
<para>
(Alan Flavell &lt;flavell+www@a5.ph.gla.ac.uk&gt; が答えます...)
</para>
<para>
The Common Gateway Interface (CGI) specifies a software interface between
a program (&quot;CGI script&quot;) and a web server (HTTPD). It is not specific
to Perl, and has its own FAQs and tutorials, and usenet group,
comp.infosystems.www.authoring.cgi
</para>
<para>
The Common Gateway Interface (CGI) はプログラム(&quot;CGI スクリプト&quot;)と
web サーバ (HTTPD) の間のソフトウェアインターフェースを定めています。
これは Perl 固有のものではないので、独自の FAQと独自のチュートリアル、
そして独自の usenet group である comp.infosystems.www.authoring.cgi が
あります。
</para>
<para>
The CGI specification is outlined in an informational RFC:
<xlink uri='http://www.ietf.org/rfc/rfc3875'>http://www.ietf.org/rfc/rfc3875</xlink>
</para>
<para>
CGI 仕様は RFC に概要が述べられています:
<xlink uri='http://www.ietf.org/rfc/rfc3875'>http://www.ietf.org/rfc/rfc3875</xlink>
</para>
<para>
Other relevant documentation listed in: <xlink uri='http://www.perl.org/CGI_MetaFAQ.html'>http://www.perl.org/CGI_MetaFAQ.html</xlink>
</para>
<para>
その他の関連する文書のリストは <xlink uri='http://www.perl.org/CGI_MetaFAQ.html'>http://www.perl.org/CGI_MetaFAQ.html</xlink> に
あります。
</para>
<para>
These Perl FAQs very selectively cover some CGI issues. However, Perl
programmers are strongly advised to use the CGI.pm module, to take care
of the details for them.
</para>
<para>
これらの Perl FAQ はいくつかの CGI の問題についてとても抜粋して
カバーしています。
しかし、これらの詳細に用心するために、Perl プログラマは CGI モジュールを
使うことを強く忠告されます。
</para>
<para>
The similarity between CGI response headers (defined in the CGI
specification) and HTTP response headers (defined in the HTTP
specification, RFC2616) is intentional, but can sometimes be confusing.
</para>
<para>
(CGI 仕様に定義されている) CGI レスポンスヘッダと、(RFC2616 の HTTP 仕様で
定義されている) HTTP レスポンスヘッダの類似性は意図的なものですが、
時々混乱を引き起こします。
</para>
<para>
The CGI specification defines two kinds of script: the &quot;Parsed Header&quot;
script, and the &quot;Non Parsed Header&quot; (NPH) script. Check your server
documentation to see what it supports. &quot;Parsed Header&quot; scripts are
simpler in various respects. The CGI specification allows any of the
usual newline representations in the CGI response (it's the server's
job to create an accurate HTTP response based on it). So &quot;\n&quot; written in
text mode is technically correct, and recommended. NPH scripts are more
tricky: they must put out a complete and accurate set of HTTP
transaction response headers; the HTTP specification calls for records
to be terminated with carriage-return and line-feed, i.e ASCII \015\012
written in binary mode.
</para>
<para>
CGI 仕様は 2 種類のスクリプトを定義しています:
&quot;Parsed Header&quot; スクリプトと、&quot;Non Parsed Header&quot; (NPH) スクリプト。
何をサポートしているかについてはサーバーのドキュメントをチェックして
ください。
&quot;Parsed Header&quot; スクリプトは色々な側面においてより単純です。
CGI 仕様は CGI レスポンスとして一般的な改行表現のどれを使ってもよいことに
なっています(そこから正確な HTTP レスポンスを作成するのはサーバの仕事です)。
従って &quot;\n&quot; をテキストモードで書くのは技術的に正しく、推奨されています。
NPH スクリプトではより微妙です: ここでは完全に正確な HTTP トランザクション
レスポンスヘッダを出力しなければなりません; HTTP 仕様はレコードが復帰と
改行(つまりバイナリモードで ASCII コードの \015\012 が書かれる)で
終端されていることを要求します。
</para>
<para>
Using CGI.pm gives excellent platform independence, including EBCDIC
systems. CGI.pm selects an appropriate newline representation
($CGI::CRLF) and sets binmode as appropriate.
</para>
<para>
CGI.pm を使うことで、EBCDIC システムを含むすばらしいプラットフォーム
独立性が得られます。
CGI.pm は適切な改行表現を選択し($CGI::CRLF)、binmode を適切にセットします。
</para>
</sect2>
<sect2>
<title>My CGI script runs from the command line but not the browser.  (500 Server Error)</title>
<para>
(私の CGI スクリプトはコマンドラインでは動くのだけど、ブラウザ上では動きません
(500 Server Error になります))
</para>
<para>
Several things could be wrong.  You can go through the &quot;Troubleshooting
Perl CGI scripts&quot; guide at
</para>
<para>
可能性はいくつかあります。
以下にある &quot;Troubleshooting Perl CGI scripts&quot; ガイドを読みましょう:
</para>
<verbatim><![CDATA[
http://www.perl.org/troubleshooting_CGI.html
]]></verbatim>
<para>
If, after that, you can demonstrate that you've read the FAQs and that
your problem isn't something simple that can be easily answered, you'll
probably receive a courteous and useful reply to your question if you
post it on comp.infosystems.www.authoring.cgi (if it's something to do
with HTTP or the CGI protocols).  Questions that appear to be Perl
questions but are really CGI ones that are posted to comp.lang.perl.misc
are not so well received.
</para>
<para>
その後、FAQ を読んで、あなたの問題が簡単に答られるものではないと
わかったのなら、(HTTP や CGI プロトコルに関するものなら)
comp.infosystems.www.authoring.cgi にポストすれば有用なリプライが
得られるでしょう。
Perl に関する質問のように見えていても、実は CGI に関するものだというものが
comp.lang.perl.misc に投稿されることがありますが、回答はついていません。
</para>
<para>
The useful FAQs, related documents, and troubleshooting guides are
listed in the CGI Meta FAQ:
</para>
<para>
便利な FAQ、関連するドキュメント、トラブルシューティングガイドは
CGI Meta FAQ に挙げられています:
</para>
<verbatim><![CDATA[
http://www.perl.org/CGI_MetaFAQ.html
]]></verbatim>
</sect2>
<sect2>
<title>How can I get better error messages from a CGI program?</title>
<para>
(CGI プログラムから、もっとまともなエラーメッセージを得るには?)
</para>
<para>
Use the CGI::Carp module.  It replaces <code>warn</code> and <code>die</code>, plus the
normal Carp modules <code>carp</code>, <code>croak</code>, and <code>confess</code> functions with
more verbose and safer versions.  It still sends them to the normal
server error log.
</para>
<para>
CGI::Carp モジュールを使いましょう。
このモジュールは <code>warn</code> と <code>die</code> の置き換えを行い、さらに通常の
Carp モジュールの <code>carp</code>、<code>croak</code>、<code>confess</code> といった関数をより饒舌で
安全なものに置き換えます。
その出力は、サーバーの通常のエラーログに送られます。
</para>
<verbatim><![CDATA[
use CGI::Carp;
warn "This is a complaint";
die "But this one is serious";
]]></verbatim>
<para>
The following use of CGI::Carp also redirects errors to a file of your choice,
placed in a BEGIN block to catch compile-time warnings as well:
</para>
<para>
以下の CGI::Carp の使用例では、エラーをあなたの選択したファイルへ
リダイレクトし、コンパイル時の警告も同様に補足するため BEGIN ブロックに
置いています:
</para>
<verbatim><![CDATA[
BEGIN {
    use CGI::Carp qw(carpout);
    open(LOG, ">>/var/local/cgi-logs/mycgi-log")
        or die "Unable to append to mycgi-log: $!\n";
    carpout(*LOG);
}
]]></verbatim>
<para>
You can even arrange for fatal errors to go back to the client browser,
which is nice for your own debugging, but might confuse the end user.
</para>
<para>
深刻なエラーをクライアントのブラウザに戻すように変更することもできます。
これはあなたがデバッグするには良いでしょうが、エンドユーザーを
混乱させてしまうかもしれません。
</para>
<verbatim><![CDATA[
use CGI::Carp qw(fatalsToBrowser);
die "Bad error here";
]]></verbatim>
<para>
Even if the error happens before you get the HTTP header out, the module
will try to take care of this to avoid the dreaded server 500 errors.
Normal warnings still go out to the server error log (or wherever
you've sent them with <code>carpout</code>) with the application name and date
stamp prepended.
</para>
<para>
あなたが HTTP ヘッダーを受け取るよりも前にエラーが起こったとしても、
モジュールはサーバーの 500 エラーを避けるためにそのエラーを取り扱おうと
するでしょう。
通常の警告はサーバーのエラーログ(もしくはあなたが <code>carpout</code> で指定した場所)に
アプリケーションの名前と日付を伴って送られます。
</para>
</sect2>
<sect2>
<title>How do I remove HTML from a string?</title>
<para>
(ある文字列から HTML を取り除くには?)
</para>
<para>
The most correct way (albeit not the fastest) is to use HTML::Parser
from CPAN.  Another mostly correct
way is to use HTML::FormatText which not only removes HTML but also
attempts to do a little simple formatting of the resulting plain text.
</para>
<para>
(最速ではありませんが)最も正しい方法は、CPAN にある HTML::Parser を
使うというものです。
もう一つのまず正しい方法は、HTML::FormatText を使って HTML を
取り除くだけでなく、結果のプレーンテキストを簡単に整形することです。
</para>
<para>
Many folks attempt a simple-minded regular expression approach, like
<code>s/&lt;.*?&gt;//g</code>, but that fails in many cases because the tags
may continue over line breaks, they may contain quoted angle-brackets,
or HTML comment may be present.  Plus, folks forget to convert
entities--like <code>&amp;lt;</code> for example.
</para>
<para>
多くの人が、<code>s/&lt;.*?&gt;//g</code> のような単純な(simple-minded)正規表現を
使ったアプローチを行おうとするのですが、これは多くの場合
失敗していまいます。
なぜなら、タグは行をまたがって継続する可能性があり、
クォートされたアングルブラケットを含む可能性があり、
HTML のコメントがあるかもしれないからです。
さらに、人々は <code>&amp;lt;</code> のようなエンティティを変換することを忘れてしまうのです。
</para>
<para>
Here's one &quot;simple-minded&quot; approach, that works for most files:
</para>
<para>
以下の例は “単純な”アプローチで、ほとんどのファイルに対しては
うまくいきます:
</para>
<verbatim><![CDATA[
#!/usr/bin/perl -p0777
s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
]]></verbatim>
<para>
If you want a more complete solution, see the 3-stage striphtml
program in
<xlink uri='http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz'>http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz</xlink>
.
</para>
<para>
もし、より完璧な解決策を求めているのなら、
<xlink uri='http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz'>http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz</xlink>
にある 3-stage striphtml プログラムを参照してみてください。
</para>
<para>
Here are some tricky cases that you should think about when picking
a solution:
</para>
<para>
以下に挙げたのは、あなたが自分でやろうとしたときに
考慮すべきであろうトリッキーな例です:
</para>
<verbatim><![CDATA[
<IMG SRC = "foo.gif" ALT = "A > B">
]]></verbatim>
<verbatim><![CDATA[
<IMG SRC = "foo.gif"
	 ALT = "A > B">
]]></verbatim>
<verbatim><![CDATA[
<!-- <A comment> -->
]]></verbatim>
<verbatim><![CDATA[
<script>if (a<b && a>c)</script>
]]></verbatim>
<verbatim><![CDATA[
<# Just data #>
]]></verbatim>
<verbatim><![CDATA[
<![INCLUDE CDATA [ >>>>>>>>>>>> ]]>]]&gt;<![CDATA[
]]></verbatim>
<para>
If HTML comments include other tags, those solutions would also break
on text like this:
</para>
<para>
以下のテキストのように HTML のコメントが他のタグを含んでいた場合には、
せっかくの対応策もダメにしてしまうかもしれません:
</para>
<verbatim><![CDATA[
<!-- This section commented out.
    <B>You can't see me!</B>
-->
]]></verbatim>
</sect2>
<sect2>
<title>How do I extract URLs?</title>
<para>
(URL の展開を行うには?)
</para>
<para>
You can easily extract all sorts of URLs from HTML with
<code>HTML::SimpleLinkExtor</code> which handles anchors, images, objects,
frames, and many other tags that can contain a URL.  If you need
anything more complex, you can create your own subclass of
<code>HTML::LinkExtor</code> or <code>HTML::Parser</code>.  You might even use
<code>HTML::SimpleLinkExtor</code> as an example for something specifically
suited to your needs.
</para>
<para>
アンカー、イメージ、オブジェクト、フレーム、およびその他の URL を含む
多くのタグを扱える <code>HTML::SimpleLinkExtor</code> を使って、HTML からあらゆる
種類の URL を簡単に抽出できます。
もしもっと複雑なものが必要なら、自分自身で <code>HTML::LinkExtor</code> や
<code>HTML::Parser</code> のサブクラスを作れます。
例えば、あなたの用途に特に適用するなら、<code>HTML::SimpleLinkExtor</code> を
使うこともできます。
</para>
<para>
You can use URI::Find to extract URLs from an arbitrary text document.
</para>
<para>
任意のテキスト文書から URL を抽出するためには、URI::Find が使えます。
</para>
<para>
Less complete solutions involving regular expressions can save
you a lot of processing time if you know that the input is simple.  One
solution from Tom Christiansen runs 100 times faster than most
module based approaches but only extracts URLs from anchors where the first
attribute is HREF and there are no other attributes.
</para>
<para>
もし入力が単純であることが分かっているなら、正規表現を使ったより不完全な
解法によって多くの処理時間を節約できます。
Tom Christiansen による一つの解法は、モジュールを使った手法よりも 100 倍
速いですが、最初の属性が HREF で、その他の属性がないアンカーの URL のみを
抽出します。
</para>
<verbatim><![CDATA[
#!/usr/bin/perl -n00
# qxurl - tchrist@perl.com
print "$2\n" while m{
    < \s*
      A \s+ HREF \s* = \s* (["']) (.*?) \1
    \s* >
}gsix;
]]></verbatim>
</sect2>
<sect2>
<title>How do I download a file from the user's machine?  How do I open a file on another machine?</title>
<para>
(ユーザーのマシンからファイルをダウンロードするには? 別のマシンにあるファイルをオープンするには?)
</para>
<para>
In this case, download means to use the file upload feature of HTML
forms.  You allow the web surfer to specify a file to send to your web
server.  To you it looks like a download, and to the user it looks
like an upload.  No matter what you call it, you do it with what's
known as <strong>multipart/form-data</strong> encoding.  The CGI.pm module (which
comes with Perl as part of the Standard Library) supports this in the
start_multipart_form() method, which isn't the same as the startform()
method.
</para>
<para>
この場合、ダウンロードというのは HTML フォームのファイルアップロード機能を
使うということを意味します。
Web サーファーに、Web サーバーに送るファイルを指定できるようにします。
あなたにとってダウンロードに見えるものは、ユーザーにとってはアップロードに
見えます。
何と呼ぶかには関わらず、<strong>multipart/form-data</strong>
エンコーディングとして知られているものを使うことができるでしょう。
CGI.pm モジュール(標準ライブラリになっています)はこれを start_multipart_form()
という starform() メソッドとは異なるメソッドでサポートしています。
</para>
<para>
See the section in the CGI.pm documentation on file uploads for code
examples and details.
</para>
<para>
コードのサンプルと詳細については、CGI.pm の文書のファイルアップロードの
章を参照してください。
</para>
</sect2>
<sect2>
<title>How do I make an HTML pop-up menu with Perl?</title>
<para>
(Perl で HTML のポップアップメニューを作るには?)
</para>
<para>
(contributed by brian d foy)
</para>
<para>
(brian d foy によって寄贈されました)
</para>
<para>
The CGI.pm module (which comes with Perl) has functions to create
the HTML form widgets. See the CGI.pm documentation for more
examples.
</para>
<para>
CGI.pm モジュール(標準配布です)には HTML フォームウィジェットを作るための
関数があります。
更なる例については CGI.pm の文書を参照してください。
</para>
<verbatim><![CDATA[
use CGI qw/:standard/;
print header,
	start_html('Favorite Animals'),
]]></verbatim>
<verbatim><![CDATA[
start_form,
	"What's your favorite animal? ",
        popup_menu(
        	-name   => 'animal',
	-values => [ qw( Llama Alpaca Camel Ram ) ]
	),
        submit,
]]></verbatim>
<verbatim><![CDATA[
end_form,
        end_html;
]]></verbatim>
</sect2>
<sect2>
<title>How do I fetch an HTML file?</title>
<para>
(HTML ファイルをフェッチするには?)
</para>
<para>
One approach, if you have the lynx text-based HTML browser installed
on your system, is this:
</para>
<para>
一つのやり方は、あなたが lynx というテキストベースの HTML ブラウザを
インストールしているとすれば、次のようなものです:
</para>
<verbatim><![CDATA[
$html_code = `lynx -source $url`;
$text_data = `lynx -dump $url`;
]]></verbatim>
<para>
The libwww-perl (LWP) modules from CPAN provide a more powerful way
to do this.  They don't require lynx, but like lynx, can still work
through proxies:
</para>
<para>
CPAN で入手できる libwww-perl (LWP) モジュールはこれを行う、
よりパワフルな方法を提供します。
これは lynx を必要とせず、プロキシ越しでも使えます:
</para>
<verbatim><![CDATA[
# simplest version
use LWP::Simple;
$content = get($URL);
]]></verbatim>
<verbatim><![CDATA[
# or print HTML from a URL
use LWP::Simple;
getprint "http://www.linpro.no/lwp/";
]]></verbatim>
<verbatim><![CDATA[
# or print ASCII from HTML from a URL
# also need HTML-Tree package from CPAN
use LWP::Simple;
use HTML::Parser;
use HTML::FormatText;
my ($html, $ascii);
$html = get("http://www.perl.com/");
defined $html
    or die "Can't fetch HTML from http://www.perl.com/";
$ascii = HTML::FormatText->new->format(parse_html($html));
print $ascii;
]]></verbatim>
</sect2>
<sect2>
<title>How do I automate an HTML form submission?</title>
<para>
(HTML フォームの処理を自動化するには?)
</para>
<para>
If you are doing something complex, such as moving through many pages
and forms or a web site, you can use <code>WWW::Mechanize</code>.  See its
documentation for all the details.
</para>
<para>
もし、複数のページとフォームや web サイトを移動するような、複雑なことを
しようとしているなら、<code>WWW::Mechanize</code> が使えます。
全ての詳細についてはこれのドキュメントを参照してください。
</para>
<para>
If you're submitting values using the GET method, create a URL and encode
the form using the <code>query_form</code> method:
</para>
<para>
GET メソッドを使って値を処理しているのであれば、URL を作って、
さらに <code>query_form</code> メソッドを使ってフォームをエンコードします:
</para>
<verbatim><![CDATA[
use LWP::Simple;
use URI::URL;
]]></verbatim>
<verbatim><![CDATA[
my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);
]]></verbatim>
<para>
If you're using the POST method, create your own user agent and encode
the content appropriately.
</para>
<para>
POST メソッドを使っているのであれば、自分用のエージェントを作成して
コンテンツを適切にエンコードしてやります。
</para>
<verbatim><![CDATA[
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
]]></verbatim>
<verbatim><![CDATA[
$ua = LWP::UserAgent->new();
my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
               [ module => 'DB_File', readme => 1 ];
$content = $ua->request($req)->as_string;
]]></verbatim>
</sect2>
<sect2>
<title>How do I decode or create those %-encodings on the web?</title>
<para>
(web上で %-encodings をデコードしたり生成したりするには?)
</para>
<para>
If you are writing a CGI script, you should be using the CGI.pm module
that comes with perl, or some other equivalent module.  The CGI module
automatically decodes queries for you, and provides an escape()
function to handle encoding.
</para>
<para>
CGI スクリプトを書いているのなら、perl に付属している CGI.pm モジュール
または等価なモジュールを使うべきです。
CGI モジュールは自動的にクエリをデコードし、escape() 関数で
エンコードもできます。
</para>
<para>
The best source of detailed information on URI encoding is RFC 2396.
Basically, the following substitutions do it:
</para>
<para>
URI エンコーディングの詳細情報に関する最良のソースは RFC 2396 です。
基本的には、以下の置換が実行されます:
</para>
<verbatim><![CDATA[
s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg;   # encode
]]></verbatim>
<verbatim><![CDATA[
s/%([A-Fa-f\d]{2})/chr hex $1/eg;                # decode
	s/%([[:xdigit:]]{2})/chr hex $1/eg;          # same thing
]]></verbatim>
<para>
However, you should only apply them to individual URI components, not
the entire URI, otherwise you'll lose information and generally mess
things up.  If that didn't explain it, don't worry.  Just go read
section 2 of the RFC, it's probably the best explanation there is.
</para>
<para>
しかし、これは URI 全体ではなく、個々の URI コンポーネントに
対して適用するべきです。
さもなければ、情報が失われ、ぐちゃぐちゃになります。
これが説明になっていなくても、心配はいりません。
RFC の第 2 章を読んでください。
おそらくこの問題に関する最良の説明です。
</para>
<para>
RFC 2396 also contains a lot of other useful information, including a
regexp for breaking any arbitrary URI into components (Appendix B).
</para>
<para>
RFC 2396 にはその他の有用な情報が多く含まれています。
その中には任意の URI をコンポーネントに分割するための
正規表現 (Appendix B) を含みます。
</para>
</sect2>
<sect2>
<title>How do I redirect to another page?</title>
<para>
(別のページにリダイレクトするには?)
</para>
<para>
Specify the complete URL of the destination (even if it is on the same
server). This is one of the two different kinds of CGI &quot;Location:&quot;
responses which are defined in the CGI specification for a Parsed Headers
script. The other kind (an absolute URLpath) is resolved internally to
the server without any HTTP redirection. The CGI specifications do not
allow relative URLs in either case.
</para>
<para>
(たとえ同じサーバでも)宛て先の完全な URL を指定してください。
これは Parsed Headers スクリプトとして CGI 仕様に定義された二つの異なった
CGI &quot;Location:&quot; レスポンスのうちの一つです。
その他の種類 (絶対 URL パス) は HTTP リダイレクトなしにサーバによって
内部的に解決されます。
CGI 仕様ではどちらの場合でも相対 URL は認められていません。
</para>
<para>
Use of CGI.pm is strongly recommended.  This example shows redirection
with a complete URL. This redirection is handled by the web browser.
</para>
<para>
CGI.pm を使うことを強くお勧めします。
この例では完全な URL へのリダイレクトを行います。
このリダイレクトは web ブラウザによって扱われます。
</para>
<verbatim><![CDATA[
use CGI qw/:standard/;
]]></verbatim>
<verbatim><![CDATA[
my $url = 'http://www.cpan.org/';
print redirect($url);
]]></verbatim>
<para>
This example shows a redirection with an absolute URLpath.  This
redirection is handled by the local web server.
</para>
<para>
この例では絶対 URL パスへのリダイレクトを行います。
このリダイレクトはローカルの web サーバによって行われます。
</para>
<verbatim><![CDATA[
my $url = '/CPAN/index.html';
print redirect($url);
]]></verbatim>
<para>
But if coded directly, it could be as follows (the final &quot;\n&quot; is
shown separately, for clarity), using either a complete URL or
an absolute URLpath.
</para>
<para>
しかし、直接コーディングするなら、完全な URL か絶対 URLpath を使って、
以下のようになります(最後の &quot;\n&quot; は明確化するために分けて表示しています)。
</para>
<verbatim><![CDATA[
print "Location: $url\n";   # CGI response header
print "\n";                 # end of headers
]]></verbatim>
</sect2>
<sect2>
<title>How do I put a password on my web pages?</title>
<para>
(私の web ぺージでパスワードを入力するには?)
</para>
<para>
To enable authentication for your web server, you need to configure
your web server.  The configuration is different for different sorts
of web servers--apache does it differently from iPlanet which does
it differently from IIS.  Check your web server documentation for
the details for your particular server.
</para>
<para>
利用する Web サーバーで認証を有効にするには、Web サーバーを設定することが
必要です。
web サーバの種類によって設定は異なります -- apache は iPlanet とは異なり、
また IIS とも異なります。
特定のサーバーに関する詳細については、そのサーバーのドキュメントを
チェックしてください。
</para>
</sect2>
<sect2>
<title>How do I edit my .htpasswd and .htgroup files with Perl?</title>
<para>
(Perl を使って .htpasswd や .htgroup といったファイルを編集するには?)
</para>
<para>
The HTTPD::UserAdmin and HTTPD::GroupAdmin modules provide a
consistent OO interface to these files, regardless of how they're
stored.  Databases may be text, dbm, Berkeley DB or any database with
a DBI compatible driver.  HTTPD::UserAdmin supports files used by the
&quot;Basic&quot; and &quot;Digest&quot; authentication schemes.  Here's an example:
</para>
<para>
HTTPD::UserAdmin モジュールと HTTPD::GroupAdmin モジュールは、
ファイルがどのように格納されているかに関係なくこれらのファイルに対する
首尾一貫したオブジェクト指向インターフェースを提供します。
データベースはテキスト、dbm、Berkeley DB、あるいは DBI 互換ドライバのある
どんなデータベースでもかまいません。
HTTPD::UserAdmin は &quot;Basic&quot; および &quot;Digest&quot; 認証スキームで
使われるファイルをサポートします。
以下に例を挙げます:
</para>
<verbatim><![CDATA[
use HTTPD::UserAdmin ();
HTTPD::UserAdmin
	  ->new(DB => "/foo/.htpasswd")
	  ->add($username => $password);
]]></verbatim>
</sect2>
<sect2>
<title>How do I make sure users can't enter values into a form that cause my CGI script to do bad things?</title>
<para>
(私の CGI スクリプトに悪影響をもたらすようなものを、ユーザーがフォームに入力できないようにするには?)
</para>
<para>
See the security references listed in the CGI Meta FAQ
</para>
<para>
CGI Meta FAQ に挙げられているセキュリティに関する参考資料を参照してください。
</para>
<verbatim><![CDATA[
http://www.perl.org/CGI_MetaFAQ.html
]]></verbatim>
</sect2>
<sect2>
<title>How do I parse a mail header?</title>
<para>
(メールのヘッダーを解析するには?)
</para>
<para>
For a quick-and-dirty solution, try this solution derived
from <link xref='perlfunc#split'>perlfunc/split</link>:
</para>
<para>
拙速な解決策なら、<link xref='perlfunc#split'>perlfunc/split</link> から派生した
以下のやり方を試してみてください。
</para>
<verbatim><![CDATA[
$/ = '';
$header = <MSG>;
$header =~ s/\n\s+/ /g;	 # merge continuation lines
%head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );
]]></verbatim>
<para>
That solution doesn't do well if, for example, you're trying to
maintain all the Received lines.  A more complete approach is to use
the Mail::Header module from CPAN (part of the MailTools package).
</para>
<para>
このやり方は、たとえば受信した行すべてを保守しようとするときには
うまくありません。
より完璧なアプローチはCPANにあるMail::Header モジュールを
使うというものです(このモジュールは MailTools パッケージの一部です)。
</para>
</sect2>
<sect2>
<title>How do I decode a CGI form?</title>
<para>
(CGI フォームをデコードするには?)
</para>
<para>
(contributed by brian d foy)
</para>
<para>
(brian d foy によって寄贈されました)
</para>
<para>
Use the CGI.pm module that comes with Perl.  It's quick,
it's easy, and it actually does quite a bit of work to
ensure things happen correctly.  It handles GET, POST, and
HEAD requests, multipart forms, multivalued fields, query
string and message body combinations, and many other things
you probably don't want to think about.
</para>
<para>
Perl に同梱されている CGI.pm モジュールを使いましょう。
これは早く、簡単で、物事が正しく行われることを確実にするための
ちょっとした作業を行います。
GET, POST, HEAD リクエスト、マルチパートフォーム、複数値フィールド、
クエリ文字列とメッセージボディの組み合わせ、およびその他の、
あなたが考えようとも思わないような多くの事柄を扱えます。
</para>
<para>
It doesn't get much easier: the CGI module automatically
parses the input and makes each value available through the
<code>param()</code> function.
</para>
<para>
これ以上簡単にはなりません: CGI モジュールは入力を自動的にパースして、
それぞれの値を <code>param()</code> 関数を通して利用可能にします。
</para>
<verbatim><![CDATA[
use CGI qw(:standard);
]]></verbatim>
<verbatim><![CDATA[
my $total = param( 'price' ) + param( 'shipping' );
]]></verbatim>
<verbatim><![CDATA[
my @items = param( 'item' ); # multiple values, same field name
]]></verbatim>
<para>
If you want an object-oriented approach, CGI.pm can do that too.
</para>
<para>
オブジェクト指向な手法が使いたいなら、CGI.pm はそのようにもできます。
</para>
<verbatim><![CDATA[
use CGI;
]]></verbatim>
<verbatim><![CDATA[
my $cgi = CGI->new();
]]></verbatim>
<verbatim><![CDATA[
my $total = $cgi->param( 'price' ) + $cgi->param( 'shipping' );
]]></verbatim>
<verbatim><![CDATA[
my @items = $cgi->param( 'item' );
]]></verbatim>
<para>
You might also try CGI::Minimal which is a lightweight version
of the same thing.  Other CGI::* modules on CPAN might work better
for you, too.
</para>
<para>
同じことをする軽量版の CGI::Minimal も試したいかもしれません。
CPAN にあるその他の CGI::* モジュールもあなたのためによく働くでしょう。
</para>
<para>
Many people try to write their own decoder (or copy one from
another program) and then run into one of the many &quot;gotchas&quot;
of the task.  It's much easier and less hassle to use CGI.pm.
</para>
<para>
多くの人々が自分用のデコーダを書こうとします (あるいは他のプログラムから
コピーしようとします); そしてこの作業の多くの「コツ」の一つに出くわすことに
なります。
CGI.pm を使うことはより簡単で、面倒事も少なくなります。
</para>
</sect2>
<sect2>
<title>How do I check a valid mail address?</title>
<para>
(メールアドレスが正しいかチェックするには?)
</para>
<para>
(partly contributed by Aaron Sherman)
</para>
<para>
(一部は Aaron Sherman によって寄贈されました)
</para>
<para>
This isn't as simple a question as it sounds.  There are two parts:
</para>
<para>
これは見た目ほど単純な質問ではありません。
これは二つの部分からなります:
</para>
<para>
a) How do I verify that an email address is correctly formatted?
</para>
<para>
a) メールアドレスが正しい形式かを検証するには?
</para>
<para>
b) How do I verify that an email address targets a valid recipient?
</para>
<para>
b) メールアドレスが正当な受信者を対象としているかを検証するには?
</para>
<para>
Without sending mail to the address and seeing whether there's a human
on the other end to answer you, you cannot fully answer part <emphasis>b</emphasis>, but
either the <code>Email::Valid</code> or the <code>RFC::RFC822::Address</code> module will do
both part <emphasis>a</emphasis> and part <emphasis>b</emphasis> as far as you can in real-time.
</para>
<para>
そのアドレスにメールを送ってそれが届いたかどうかを確認しなければ
完全にパート <emphasis>b</emphasis> に答えられませんが、<code>Email::Valid</code> か 
<code>RFC::RFC822::Address</code> のモジュールは、リアルタイムでできる限りの
ことに対してパート <emphasis>a</emphasis> とパート <emphasis>b</emphasis> の両方を行います。
</para>
<para>
If you want to just check part <emphasis>a</emphasis> to see that the address is valid
according to the mail header standard with a simple regular expression,
you can have problems, because there are deliverable addresses that
aren't RFC-2822 (the latest mail header standard) compliant, and
addresses that aren't deliverable which, are compliant.  However,  the
following will match valid RFC-2822 addresses that do not have comments,
folding whitespace, or any other obsolete or non-essential elements.
This <emphasis>just</emphasis> matches the address itself:
</para>
<para>
もしあなたが単純な正規表現でアドレスがメールヘッダ標準に従っているかを
見ることでパート <emphasis>a</emphasis> をチェックしたいなら、問題を抱えることになります;
なぜなら、RFC-2822 (最新のメールヘッダ標準) に準拠してないけれども
配達可能なアドレスが存在し、標準に準拠しているけれども配達不能なアドレスも
存在するからです。
しかし以下のコードは、コメント、折り畳みの空白、あるいはその他の時代遅れに
なっていたり本質的でない要素を含んでいない、有効な RFC-2822 アドレスに
マッチングします。
これは <emphasis>単に</emphasis> アドレス自身にマッチングします:
</para>
<verbatim><![CDATA[
my $atom       = qr{[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+};
my $dot_atom   = qr{$atom(?:\.$atom)*};
my $quoted     = qr{"(?:\\[^\r\n]|[^\\"])*"};
my $local      = qr{(?:$dot_atom|$quoted)};
my $domain_lit = qr{\[(?:\\\S|[\x21-\x5a\x5e-\x7e])*\]};
my $domain     = qr{(?:$dot_atom|$domain_lit)};
my $addr_spec  = qr{$local\@$domain};
]]></verbatim>
<para>
Just match an address against <code>/^${addr_spec}$/</code> to see if it follows
the RFC2822 specification.  However, because it is impossible to be
sure that such a correctly formed address is actually the correct way
to reach a particular person or even has a mailbox associated with it,
you must be very careful about how you use this.
</para>
<para>
もしアドレスが RFC 2822 仕様に準拠しているかどうかを見たいなら、単に
<code>/^${addr_spec}$/</code> とマッチングさせてください。
しかし、このような正しい形式のアドレスが実際に特定の個人に届く
正しい方法なのか、あるいはその個人に関連付けられたメールボックスに
届くのかさえも明確にすることは不可能なので、これをどう使うかについては
とても慎重になる必要があります。
</para>
<para>
Our best advice for verifying a person's mail address is to have them
enter their address twice, just as you normally do to change a
password. This usually weeds out typos. If both versions match, send
mail to that address with a personal message. If you get the message
back and they've followed your directions, you can be reasonably
assured that it's real.
</para>
<para>
私たちができる最善のアドバイスは、個人のメールアドレスをチェックするのに
パスワードを変更するときと同じようにユーザーにアドレスを
二回入力させるというものです。
これによって通常は打ち間違いを防ぐことができます。
二回の入力がマッチしたなら、個人的な内容のメッセージをメールとして
そのアドレスへ送ります。
もしメッセージが返ってきて、それがあなたの指示に従っているなら、
それが実際のものであると十分に仮定できます。
</para>
<para>
A related strategy that's less open to forgery is to give them a PIN
(personal ID number).  Record the address and PIN (best that it be a
random one) for later processing. In the mail you send, ask them to
include the PIN in their reply.  But if it bounces, or the message is
included via a &quot;vacation&quot; script, it'll be there anyway.  So it's
best to ask them to mail back a slight alteration of the PIN, such as
with the characters reversed, one added or subtracted to each digit, etc.
</para>
<para>
より偽造のやりにくい別のやり方に、チェックに対象者に対して PIN
(Personal ID Number) を与えるというものがあります。
後の処理のためにアドレスと PIN (ランダムであることが望ましい)を
記録しておくのです。
あなたがメールを送るときに、宛て先人に対して彼らの出すリプライに
PIN を含めるように依頼するのです。
しかしそれがそのまま返ってきたり、あるいは返ってきたメッセージが
&quot;vacation&quot; スクリプトを通じてのものであっても、そのまま PIN が
含まれてしまいます。
ですから、最善なやり方はメールを送るときに返事には文字を逆順にするとか、
各桁に対して足し算や引き算を行うなどして
PIN を変形したものを含めて返すように依頼するという方法です。
</para>
</sect2>
<sect2>
<title>How do I decode a MIME/BASE64 string?</title>
<para>
(MIME/BASE64 文字列のデコードを行うには?)
</para>
<para>
The MIME-Base64 package (available from CPAN) handles this as well as
the MIME/QP encoding.  Decoding BASE64 becomes as simple as:
</para>
<para>
MIME-Base64 パッケージ(CPAN で入手可能です)はこの問題と、
MIME/QP エンコーディングを取り扱います。
BASE64 のデコードは以下のように単純です:
</para>
<verbatim><![CDATA[
use MIME::Base64;
$decoded = decode_base64($encoded);
]]></verbatim>
<para>
The MIME-Tools package (available from CPAN) supports extraction with
decoding of BASE64 encoded attachments and content directly from email
messages.
</para>
<para>
MIME-Tools パッケージ (CPAN にあります) は BASE64 エンコードされた
添付ファイルと本文をメールのメッセージから直接抽出できます。
</para>
<para>
If the string to decode is short (less than 84 bytes long)
a more direct approach is to use the unpack() function's &quot;u&quot;
format after minor transliterations:
</para>
<para>
もしデコードしたい文字列が短い(84 文字以下)の場合、より直接的なやり方は、
ちょっとした変換をした後で unpack() 関数の &quot;u&quot; フォーマットを
使うというものです:
</para>
<verbatim><![CDATA[
tr#A-Za-z0-9+/##cd;                   # remove non-base64 chars
tr#A-Za-z0-9+/# -_#;                  # convert to uuencoded format
$len = pack("c", 32 + 0.75*length);   # compute length byte
print unpack("u", $len . $_);         # uudecode and print
]]></verbatim>
</sect2>
<sect2>
<title>How do I return the user's mail address?</title>
<para>
(ユーザーのメールアドレスを返すには?)
</para>
<para>
On systems that support getpwuid, the $&lt; variable, and the
Sys::Hostname module (which is part of the standard perl distribution),
you can probably try using something like this:
</para>
<para>
getpwuid をサポートしているシステムであれば、$&lt; という変数と
Sys::Hostname モジュール(標準の perl 配布キットの一部です)を使って
以下のようなことが試せるでしょう。
</para>
<verbatim><![CDATA[
use Sys::Hostname;
$address = sprintf('%s@%s', scalar getpwuid($<), hostname);
]]></verbatim>
<para>
Company policies on mail address can mean that this generates addresses
that the company's mail system will not accept, so you should ask for
users' mail addresses when this matters.  Furthermore, not all systems
on which Perl runs are so forthcoming with this information as is Unix.
</para>
<para>
会社のメールアドレスに関するポリシーが、これが生成するアドレスは
その会社のメールシステムが受け付けないものである可能性があります。
ですから、ユーザーに、そのユーザーのメールアドレスを尋ねるべきでしょう。
それに加え、Perl が動作する全てのシステムで
この情報が(UNIX と同じように)得られるわけではありません。
</para>
<para>
The Mail::Util module from CPAN (part of the MailTools package) provides a
mailaddress() function that tries to guess the mail address of the user.
It makes a more intelligent guess than the code above, using information
given when the module was installed, but it could still be incorrect.
Again, the best way is often just to ask the user.
</para>
<para>
CPAN にある Mail::Util モジュール (MailTools パッケージの一部です)は
メールアドレスがそのユーザーのものであるかどうかを確かめようとする
mailaddress() という関数を提供しています。
これは上で例示したやり方よりも賢く、モジュールがインストールされたときの
情報を使いますが、それでも正しくない可能性があります。
くり返しますが、最善の方法はユーザーに尋ねること、というのがほとんどです。
</para>
</sect2>
<sect2>
<title>How do I send mail?</title>
<para>
(メールを送るには?)
</para>
<para>
Use the <code>sendmail</code> program directly:
</para>
<para>
<code>sendmail</code> プログラムを直接使います:
</para>
<verbatim><![CDATA[
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
                    or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: User Originating Mail <me\@host>
To: Final Destination <you\@otherhost>
Subject: A relevant subject line
]]></verbatim>
<verbatim><![CDATA[
Body of the message goes here after the blank line
in as many lines as you like.
EOF
close(SENDMAIL)     or warn "sendmail didn't close nicely";
]]></verbatim>
<para>
The <strong>-oi</strong> option prevents sendmail from interpreting a line consisting
of a single dot as &quot;end of message&quot;.  The <strong>-t</strong> option says to use the
headers to decide who to send the message to, and <strong>-odq</strong> says to put
the message into the queue.  This last option means your message won't
be immediately delivered, so leave it out if you want immediate
delivery.
</para>
<para>
<strong>-oi</strong> オプションは sendmail がドットだけの行を“メッセージの終わり”と
みなさないようにするためのオプションです。
<strong>-t</strong>オプションはメッセージを誰に送るかを決めるかのために
ヘッダーを使うことを指示し、<strong>-odq</strong> オプションメッセージを
キューに入れることを指示します。
最後のオプションの意味は、あなたのメッセージがすぐには配送されないことを
意味します。
ですから、すぐに配送させたいのであればこのオプションを取り除いてください。
</para>
<para>
Alternate, less convenient approaches include calling mail (sometimes
called mailx) directly or simply opening up port 25 have having an
intimate conversation between just you and the remote SMTP daemon,
probably sendmail.
</para>
<para>
あるいは、直接 mail (mailx と呼ばれることもあります)を呼びだしたり、
単純に 25 番ポートを使ってリモートの SMTP デーモン(多分 sendmail でしょう)
との間で詳細な通信を行うといったあまり便利でない方法もあります。
</para>
<para>
Or you might be able use the CPAN module Mail::Mailer:
</para>
<para>
あるいは CPAN にあるモジュール Mail::Mailer が使えるかもしれません:
</para>
<verbatim><![CDATA[
use Mail::Mailer;
]]></verbatim>
<verbatim><![CDATA[
$mailer = Mail::Mailer->new();
$mailer->open({ From    => $from_address,
                To      => $to_address,
                Subject => $subject,
              })
    or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();
]]></verbatim>
<para>
The Mail::Internet module uses Net::SMTP which is less Unix-centric than
Mail::Mailer, but less reliable.  Avoid raw SMTP commands.  There
are many reasons to use a mail transport agent like sendmail.  These
include queuing, MX records, and security.
</para>
<para>
Mail::Internet モジュールは Mail::Mailer より UNIX 的ではない
Net::SMTP を使っていますが、信頼性も低いです。
生の SMTP コマンドを無視します。
sendmail のような mail transport agent を使う理由はたくさんあります。
その中にはキューイングも含まれますし、MX レコードやセキュリティと
いったものが含まれます。
</para>
</sect2>
<sect2>
<title>How do I use MIME to make an attachment to a mail message?</title>
<para>
(メールメッセージに添付するためにどうやって MIME を使えばいいですか?)
</para>
<para>
This answer is extracted directly from the MIME::Lite documentation.
Create a multipart message (i.e., one with attachments).
</para>
<para>
この回答は MIME::Lite のドキュメントから直接持ってきたものです。
マルチパートメッセージ(つまり 添付つきのメッセージ) を作ります。
</para>
<verbatim><![CDATA[
use MIME::Lite;
]]></verbatim>
<verbatim><![CDATA[
### Create a new multipart message:
$msg = MIME::Lite->new(
             From    =>'me@myhost.com',
             To      =>'you@yourhost.com',
             Cc      =>'some@other.com, some@more.com',
             Subject =>'A message with 2 parts...',
             Type    =>'multipart/mixed'
             );
]]></verbatim>
<verbatim><![CDATA[
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type     =>'TEXT',
             Data     =>"Here's the GIF file you wanted"
             );
$msg->attach(Type     =>'image/gif',
             Path     =>'aaa000123.gif',
             Filename =>'logo.gif'
             );
]]></verbatim>
<verbatim><![CDATA[
$text = $msg->as_string;
]]></verbatim>
<para>
MIME::Lite also includes a method for sending these things.
</para>
<para>
MIME::Lite はまたこれらのものを送るためのメソッドを含みます。
</para>
<verbatim><![CDATA[
$msg->send;
]]></verbatim>
<para>
This defaults to using <link xref='sendmail'>sendmail</link> but can be customized to use
SMTP via <link xref='Net::SMTP'>Net::SMTP</link>.
</para>
<para>
これはデフォルトでは <link xref='sendmail'>sendmail</link> を使いますが、
<link xref='Net::SMTP'>Net::SMTP</link> 経由で SMTP を使うようにカスタマイズできます。
</para>
</sect2>
<sect2>
<title>How do I read mail?</title>
<para>
(メールを読み出すには?)
</para>
<para>
While you could use the Mail::Folder module from CPAN (part of the
MailFolder package) or the Mail::Internet module from CPAN (part
of the MailTools package), often a module is overkill.  Here's a
mail sorter.
</para>
<para>
CPAN にある Mail::Folder モジュール(MailFolder パッケージの一部です)や
Mail::Internet モジュール(これも MailTools パッケージの一部です)が
使えますが、モジュールを使うのはやりすぎかもしれません。
以下にメールをソートする方法を示します。
</para>
<verbatim><![CDATA[
#!/usr/bin/perl
]]></verbatim>
<verbatim><![CDATA[
my(@msgs, @sub);
my $msgno = -1;
$/ = '';                    # paragraph reads
while (<>) {
    if (/^From /m) {
        /^Subject:\s*(?:Re:\s*)*(.*)/mi;
        $sub[++$msgno] = lc($1) || '';
    }
    $msgs[$msgno] .= $_;
}
for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) {
    print $msgs[$i];
}
]]></verbatim>
<para>
Or more succinctly,
</para>
<para>
あるいはもっと簡潔に:
</para>
<verbatim><![CDATA[
#!/usr/bin/perl -n00
# bysub2 - awkish sort-by-subject
BEGIN { $msgno = -1 }
$sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m;
$msg[$msgno] .= $_;
END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] }
]]></verbatim>
</sect2>
<sect2>
<title>How do I find out my hostname, domainname, or IP address?
<index>hostname, domainname, IP address, host, domain, hostfqdn, inet_ntoa,
gethostbyname, Socket, Net::Domain, Sys::Hostname</index></title>
<para>
(私のホスト名/ドメイン名/IP アドレスを見つけるには?)
</para>
<para>
(contributed by brian d foy)
</para>
<para>
(brian d foy によって寄贈されました)
</para>
<para>
The Net::Domain module, which is part of the standard distribution starting
in perl5.7.3, can get you the fully qualified domain name (FQDN), the host
name, or the domain name.
</para>
<para>
perl5.7.3 から標準配布されている Net::Domain モジュールを使うと、
完全修飾ドメイン名 (FQDN)、ホスト名、ドメイン名が得られます。
</para>
<verbatim><![CDATA[
use Net::Domain qw(hostname hostfqdn hostdomain);
]]></verbatim>
<verbatim><![CDATA[
my $host = hostfqdn();
]]></verbatim>
<para>
The <code>Sys::Hostname</code> module, included in the standard distribution since
perl5.6, can also get the hostname.
</para>
<para>
perl5.6 から標準配布されている <code>Sys::Hostname</code> モジュールでも
ホスト名を得られます。
</para>
<verbatim><![CDATA[
use Sys::Hostname;
]]></verbatim>
<verbatim><![CDATA[
$host = hostname();
]]></verbatim>
<para>
To get the IP address, you can use the <code>gethostbyname</code> built-in function
to turn the name into a number. To turn that number into the dotted octet
form (a.b.c.d) that most people expect, use the <code>inet_ntoa</code> function
from the &lt;Socket&gt; module, which also comes with perl.
</para>
<para>
IP アドレスを得るには、名前から数値に変換するために <code>gethostbyname</code>
組み込み関数が使えます。
数値を、ほとんどの人が想定しているピリオド付きの形 (a.b.c.d) に変換するには、
標準配布されている <code>Socket</code> モジュールの <code>inet_ntoa</code> 関数を使います。
</para>
<verbatim><![CDATA[
use Socket;
]]></verbatim>
<verbatim><![CDATA[
my $address = inet_ntoa(
	scalar gethostbyname( $host || 'localhost' )
	);
]]></verbatim>
</sect2>
<sect2>
<title>How do I fetch a news article or the active newsgroups?</title>
<para>
(ニュースの記事やアクティブなニュースグループを取得するには?)
</para>
<para>
Use the Net::NNTP or News::NNTPClient modules, both available from CPAN.
This can make tasks like fetching the newsgroup list as simple as
</para>
<para>
Net::NNTP モジュールか News::NNTPClient モジュールのいずれかを使います。
これらは両方ともCPANから入手可能です。
これらは以下のように簡単にニュースグループのリストを取得するような
作業ができます。
</para>
<verbatim><![CDATA[
perl -MNews::NNTPClient
  -e 'print News::NNTPClient->new->list("newsgroups")'
]]></verbatim>
</sect2>
<sect2>
<title>How do I fetch/put an FTP file?</title>
<para>
(FTP ファイルをダウンロード/アップロードするには?)
</para>
<para>
LWP::Simple (available from CPAN) can fetch but not put.  Net::FTP (also
available from CPAN) is more complex but can put as well as fetch.
</para>
<para>
LWP::Simple (CPAN で入手可能)はダウンロードができますが
アップロードはできません。
Net::FTP(これも CPAN で入手可能)はこれよりも複雑ですが、
ダウンロードとアップロードの両方ができます。
</para>
</sect2>
<sect2>
<title>How can I do RPC in Perl?</title>
<para>
(Perl で RPC を行うには?)
</para>
<para>
(Contributed by brian d foy)
</para>
<para>
(brian d foy によって寄贈されました)
</para>
<para>
Use one of the RPC modules you can find on CPAN (
<xlink uri='http://search.cpan.org/search?query=RPC&amp;mode=all'>http://search.cpan.org/search?query=RPC&amp;mode=all</xlink> ).
</para>
<para>
CPAN ( <xlink uri='http://search.cpan.org/search?query=RPC&amp;mode=all'>http://search.cpan.org/search?query=RPC&amp;mode=all</xlink> ) で見付かる
RFC モジュールの一つを使いましょう。
</para>
</sect2>
</sect1>
<sect1>
<title>REVISION</title>
<para>
Revision: $Revision: 8539 $
</para>
<para>
Date: $Date: 2007-01-11 00:07:14 +0100 (Thu, 11 Jan 2007) $
</para>
<para>
See <link xref='perlfaq'>perlfaq</link> for source control details and availability.
</para>
</sect1>
<sect1>
<title>AUTHOR AND COPYRIGHT</title>
<para>
Copyright (c) 1997-2007 Tom Christiansen, Nathan Torkington, and
other authors as noted. All rights reserved.
</para>
<para>
This documentation is free; you can redistribute it and/or modify it
under the same terms as Perl itself.
</para>
<para>
Irrespective of its distribution, all code examples in this file
are hereby placed into the public domain.  You are permitted and
encouraged to use this code in your own programs for fun
or for profit as you see fit.  A simple comment in the code giving
credit would be courteous but is not required.
</para>
</sect1>
</pod>
