=encoding euc-jp =head1 NAME =begin original perlfaq9 - Networking =end original perlfaq9 - �ͥåȥ�� =head1 DESCRIPTION =begin original This section deals with questions related to networking, the internet, and a few on the web. =end original ���Υ��������Ǥϡ��ͥåȥ�������󥿡��ͥåȡ�web �˴ؤ��� ����򰷤äƤ��ޤ��� =head2 What is the correct form of response from a CGI script? (CGI ������ץȤ��������������������?) =begin original (Alan Flavell answers...) =end original (Alan Flavell �������ޤ�...) =begin original The Common Gateway Interface (CGI) specifies a software interface between a program ("CGI script") 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 =end original The Common Gateway Interface (CGI) �ϥץ������("CGI ������ץ�")�� web ������ (HTTPD) �δ֤Υ��եȥ��������󥿡��ե����������Ƥ��ޤ��� ����� Perl ��ͭ�Τ�ΤǤϤʤ��Τǡ��ȼ��� FAQ���ȼ��Υ��塼�ȥꥢ�롢 �������ȼ��� usenet group �Ǥ��� comp.infosystems.www.authoring.cgi �� ����ޤ��� =begin original The CGI specification is outlined in an informational RFC: http://www.ietf.org/rfc/rfc3875 =end original CGI ���ͤ� RFC �˳��פ��Ҥ٤��Ƥ��ޤ�: http://www.ietf.org/rfc/rfc3875 =begin original These Perl FAQs very selectively cover some CGI issues. However, Perl programmers are strongly advised to use the C module, to take care of the details for them. =end original ������ Perl FAQ �Ϥ����Ĥ��� CGI ������ˤĤ��ƤȤƤ�ȴ�褷�� ���С����Ƥ��ޤ��� �������������ξܺ٤��ѿ����뤿��ˡ�Perl �ץ�����ޤ� C �⥸�塼��� �Ȥ����Ȥ򶯤���𤵤�ޤ��� =begin original 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. =end original (CGI ���ͤ��������Ƥ���) CGI �쥹�ݥ󥹥إå��ȡ�(RFC2616 �� HTTP ���ͤ� �������Ƥ���) HTTP �쥹�ݥ󥹥إå���������ϰտ�Ū�ʤ�ΤǤ����� �������������������ޤ��� =begin original The CGI specification defines two kinds of script: the "Parsed Header" script, and the "Non Parsed Header" (NPH) script. Check your server documentation to see what it supports. "Parsed Header" 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 "\n" 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. =end original CGI ���ͤ� 2 ����Υ�����ץȤ�������Ƥ��ޤ�: "Parsed Header" ������ץȤȡ�"Non Parsed Header" (NPH) ������ץȡ� ���򥵥ݡ��Ȥ��Ƥ��뤫�ˤĤ��Ƥϥ����С��Υɥ�����Ȥ�����å����� ���������� "Parsed Header" ������ץȤϿ�����¦�̤ˤ����Ƥ��ñ��Ǥ��� CGI ���ͤ� CGI �쥹�ݥ󥹤Ȥ��ư���Ū�ʲ���ɽ���Τɤ��ȤäƤ�褤���Ȥ� �ʤäƤ��ޤ�(�����������Τ� HTTP �쥹�ݥ󥹤��������Τϥ����ФλŻ��Ǥ�)�� ���ä� "\n" ��ƥ����ȥ⡼�ɤǽ񤯤Τϵ���Ū�����������侩����Ƥ��ޤ��� NPH ������ץȤǤϤ����̯�Ǥ�: �����Ǥϴ��������Τ� HTTP �ȥ�󥶥������ �쥹�ݥ󥹥إå�����Ϥ��ʤ���Фʤ�ޤ���; HTTP ���ͤϥ쥳���ɤ������� ����(�Ĥޤ�Х��ʥ�⡼�ɤ� ASCII �����ɤ� \015\012 ���񤫤��)�� ��ü����Ƥ��뤳�Ȥ��׵ᤷ�ޤ��� =begin original Using C gives excellent platform independence, including EBCDIC systems. C selects an appropriate newline representation (C<$CGI::CRLF>) and sets binmode as appropriate. =end original C ��Ȥ����Ȥǡ�EBCDIC �����ƥ��ޤह�Ф餷���ץ�åȥե����� ��Ω���������ޤ��� C ��Ŭ�ڤʲ���ɽ��������(C<$CGI::CRLF>)��binmode ��Ŭ�ڤ˥��åȤ��ޤ��� =head2 My CGI script runs from the command line but not the browser. (500 Server Error) (��� CGI ������ץȤϥ��ޥ�ɥ饤��Ǥ�ư���Τ����ɡ��֥饦����Ǥ�ư���ޤ��� (500 Server Error �ˤʤ�ޤ�)) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original There are many things that might be wrong with your CGI program, and only some of them might be related to Perl. Try going through the troubleshooting guide on Perlmonks: =end original CGI �ץ�����ब�������⤷��ʤ������Ĥ��Τ��Ȥ����ꡢ���ΰ��������� Perl �˴�Ϣ���ޤ��� Perlmonks �ˤ��ȥ�֥륷�塼�ƥ��󥰤��ǧ���ƤߤƤ�������: http://www.perlmonks.org/?node_id=380424 =head2 How can I get better error messages from a CGI program? (CGI �ץ�����फ�顢��äȤޤȤ�ʥ��顼��å�����������ˤ�?) =begin original Use the C module. It replaces C and C, plus the normal C module's C, C, and C functions with more verbose and safer versions. It still sends them to the normal server error log. =end original C �⥸�塼���Ȥ��ޤ��礦�� ���Υ⥸�塼��� C �� C ���֤�������Ԥ���������̾�� C �⥸�塼��� C��C��C �Ȥ��ä��ؿ���������� �����ʤ�Τ��֤������ޤ��� ���ν��Ϥϡ������С����̾�Υ��顼�����������ޤ��� use CGI::Carp; warn "This is a complaint"; die "But this one is serious"; =begin original The following use of C also redirects errors to a file of your choice, placed in a C block to catch compile-time warnings as well: =end original �ʲ��� C �λ�����Ǥϡ����顼�򤢤ʤ������򤷤��ե������ ������쥯�Ȥ�������ѥ�����ηٹ��Ʊ�ͤ���­���뤿�� C �֥��å��� �֤��Ƥ��ޤ�: 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); } =begin original 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. =end original ����ʥ��顼�򥯥饤����ȤΥ֥饦�����᤹�褦���ѹ����뤳�Ȥ�Ǥ��ޤ��� ����Ϥ��ʤ����ǥХå�����ˤ��ɤ��Ǥ��礦��������ɥ桼������ ���𤵤��Ƥ��ޤ����⤷��ޤ��� use CGI::Carp qw(fatalsToBrowser); die "Bad error here"; =begin original 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 C) with the application name and date stamp prepended. =end original ���ʤ��� HTTP �إå�����������������˥��顼�������ä��Ȥ��Ƥ⡢ �⥸�塼��ϥ����С��� 500 ���顼���򤱤뤿��ˤ��Υ��顼���갷������ ����Ǥ��礦�� �̾�ηٹ�ϥ����С��Υ��顼����(�⤷���Ϥ��ʤ��� C �ǻ��ꤷ�����)�� ���ץꥱ��������̾�������դ�ȼ�ä������ޤ��� =head2 How do I remove HTML from a string? (����ʸ���󤫤� HTML ��������ˤ�?) =begin original The most correct way (albeit not the fastest) is to use C from CPAN. Another mostly correct way is to use C which not only removes HTML but also attempts to do a little simple formatting of the resulting plain text. =end original (��®�ǤϤ���ޤ���)�Ǥ���������ˡ�ϡ�CPAN �ˤ��� C �� �Ȥ��Ȥ�����ΤǤ��� �⤦��ĤΤޤ���������ˡ�ϡ�C ��Ȥä� HTML �� �����������Ǥʤ�����̤Υץ졼��ƥ����Ȥ��ñ���������뤳�ȤǤ��� =begin original Many folks attempt a simple-minded regular expression approach, like C<< s/<.*?>//g >>, but that fails in many cases because the tags may continue over line breaks, they may contain quoted angle-brackets, or HTML comments may be present. Plus, folks forget to convert entities--like C<<> for example. =end original ¿���οͤ���C<< s/<.*?>//g >> �Τ褦��ñ���(simple-minded)����ɽ���� �Ȥä����ץ�������Ԥ����Ȥ���ΤǤ����������¿���ξ�� ���Ԥ��Ƥ��ޤ��ޤ��� �ʤ��ʤ顢�����ϹԤ�ޤ����äƷ�³�����ǽ�������ꡢ �������Ȥ��줿���󥰥�֥饱�åȤ�ޤ��ǽ�������ꡢ HTML �Υ����Ȥ����뤫�⤷��ʤ�����Ǥ��� ����ˡ��͡��� C<<> �Τ褦�ʥ���ƥ��ƥ����Ѵ����뤳�Ȥ�˺��Ƥ��ޤ��ΤǤ��� =begin original Here's one "simple-minded" approach, that works for most files: =end original �ʲ�����ϡ�ñ��ʡץ��ץ������ǡ��ۤȤ�ɤΥե�������Ф��Ƥ� ���ޤ������ޤ�: #!/usr/bin/perl -p0777 s/<(?:[^>'"]*|(['"]).*?\g1)*>//gs =begin original If you want a more complete solution, see the 3-stage striphtml program in http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz . =end original �⤷����괰���ʲ�������Ƥ���Τʤ顢 http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz �ˤ��� 3-stage striphtml �ץ������򻲾Ȥ��ƤߤƤ��������� =begin original Here are some tricky cases that you should think about when picking a solution: =end original �ʲ��˵󤲤��Τϡ����ʤ�����ʬ�Ǥ�����Ȥ����Ȥ��� ��θ���٤��Ǥ������ȥ�å�������Ǥ�: A > B A > B <# Just data #> >>>>>>>>>>> ]]> =begin original If HTML comments include other tags, those solutions would also break on text like this: =end original �ʲ��Υƥ����ȤΤ褦�� HTML �Υ����Ȥ�¾�Υ�����ޤ�Ǥ������ˤϡ� ���ä������б��������ˤ��Ƥ��ޤ����⤷��ޤ���: =head2 How do I extract URLs? (URL ��Ÿ����Ԥ��ˤ�?) =begin original You can easily extract all sorts of URLs from HTML with C 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 C or C. You might even use C as an example for something specifically suited to your needs. =end original ���󥫡������᡼�������֥������ȡ��ե졼�ࡢ����Ӥ���¾�� URL ��ޤ� ¿���Υ����򰷤��� C ��Ȥäơ�HTML ���餢���� ����� URL ���ñ����ФǤ��ޤ��� �⤷��ä�ʣ���ʤ�Τ�ɬ�פʤ顢��ʬ���Ȥ� C �� C �Υ��֥��饹����ޤ��� �㤨�С����ʤ������Ӥ��ä�Ŭ�Ѥ���ʤ顢C �� �Ȥ����Ȥ�Ǥ��ޤ��� =begin original You can use C to extract URLs from an arbitrary text document. =end original Ǥ�դΥƥ�����ʸ�񤫤� URL ����Ф��뤿��ˤϡ�C ���Ȥ��ޤ��� =begin original 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. =end original �⤷���Ϥ�ñ��Ǥ��뤳�Ȥ�ʬ���äƤ���ʤ顢����ɽ����Ȥä�����Դ����� ��ˡ�ˤ�ä�¿���ν������֤�����Ǥ��ޤ��� Tom Christiansen �ˤ���Ĥβ�ˡ�ϡ��⥸�塼���Ȥä���ˡ���� 100 �� ®���Ǥ������ǽ��°���� HREF �ǡ�����¾��°�����ʤ����󥫡��� URL �Τߤ� ��Ф��ޤ��� #!/usr/bin/perl -n00 # qxurl - tchrist@perl.com print "$2\n" while m{ < \s* A \s+ HREF \s* = \s* (["']) (.*?) \g1 \s* > }gsix; =head2 How do I download a file from the user's machine? How do I open a file on another machine? (�桼�����Υޥ��󤫤�ե���������������ɤ���ˤ�? �̤Υޥ���ˤ���ե�����򥪡��ץ󤹤�ˤ�?) =begin original 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 B encoding. The C module (which comes with Perl as part of the Standard Library) supports this in the C method, which isn't the same as the C method. =end original ���ξ�硢����������ɤȤ����Τ� HTML �ե�����Υե����륢�åץ����ɵ�ǽ�� �Ȥ��Ȥ������Ȥ��̣���ޤ��� Web �����ե����ˡ�Web �����С�������ե���������Ǥ���褦�ˤ��ޤ��� ���ʤ��ˤȤäƥ���������ɤ˸������Τϡ��桼�����ˤȤäƤϥ��åץ����ɤ� �����ޤ��� ���ȸƤ֤��ˤϴؤ�餺��B ���󥳡��ǥ��󥰤Ȥ����Τ��Ƥ����Τ�Ȥ����Ȥ��Ǥ���Ǥ��礦�� C �⥸�塼��(ɸ��饤�֥��ˤʤäƤ��ޤ�)�Ϥ���� C �Ȥ��� C �᥽�åɤȤϰۤʤ�᥽�åɤǥ��ݡ��Ȥ��Ƥ��ޤ��� =begin original See the section in the C documentation on file uploads for code examples and details. =end original �����ɤΥ���ץ�Ⱦܺ٤ˤĤ��Ƥϡ�C ��ʸ��Υե����륢�åץ����ɤ� �Ϥ򻲾Ȥ��Ƥ��������� =head2 How do I make an HTML pop-up menu with Perl? (Perl �� HTML �Υݥåץ��åץ�˥塼����ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original The C module (which comes with Perl) has functions to create the HTML form widgets. See the C documentation for more examples. =end original C �⥸�塼��(ɸ�����ۤǤ�)�ˤ� HTML �ե����०�������åȤ��뤿��� �ؿ�������ޤ��� ���ʤ���ˤĤ��Ƥ� C ��ʸ��򻲾Ȥ��Ƥ��������� use CGI qw/:standard/; print header, start_html('Favorite Animals'), start_form, "What's your favorite animal? ", popup_menu( -name => 'animal', -values => [ qw( Llama Alpaca Camel Ram ) ] ), submit, end_form, end_html; =head2 How do I fetch an HTML file? (HTML �ե������ե��å�����ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original Use the libwww-perl distribution. The C module can fetch web resources and give their content back to you as a string: =end original libwww-perl �ǥ����ȥ�ӥ塼������ȤäƤ��������� C �ϥ����־�Υ꥽������ե��å����ơ��������Ƥ�ʸ����Ȥ��� �֤��ޤ�: use LWP::Simple qw(get); my $html = get( "http://www.example.com/index.html" ); =begin original It can also store the resource directly in a file: =end original �꥽������ľ�ܥե��������¸���뤳�Ȥ�Ǥ��ޤ�: use LWP::Simple qw(getstore); getstore( "http://www.example.com/index.html", "foo.html" ); =begin original If you need to do something more complicated, you can use C module to create your own user-agent (e.g. browser) to get the job done. If you want to simulate an interactive web browser, you can use the C module. =end original ��ä�ʣ���ʤ��Ȥ򤹤�ɬ�פ�������ϡ��Ż���Ԥ�������ȼ��� �桼���������������(�㤨�Х֥饦��)���뤿��� C �⥸�塼���Ȥ��ޤ��� ����Ū�ʥ����֥֥饦���򥷥ߥ�졼�Ȥ��������ϡ� C �⥸�塼�뤬�Ȥ��ޤ��� =head2 How do I automate an HTML form submission? (HTML �ե�����ν�����ư������ˤ�?) =begin original If you are doing something complex, such as moving through many pages and forms or a web site, you can use C. See its documentation for all the details. =end original �⤷��ʣ���Υڡ����ȥե������ web �����Ȥ��ư����褦�ʡ�ʣ���ʤ��Ȥ� ���褦�Ȥ��Ƥ���ʤ顢C ���Ȥ��ޤ��� ���Ƥξܺ٤ˤĤ��ƤϤ���Υɥ�����Ȥ򻲾Ȥ��Ƥ��������� =begin original If you're submitting values using the GET method, create a URL and encode the form using the C method: =end original GET �᥽�åɤ�Ȥä��ͤ�������Ƥ���ΤǤ���С�URL ���äơ� ����� C �᥽�åɤ�Ȥäƥե�����򥨥󥳡��ɤ��ޤ�: use LWP::Simple; use URI::URL; my $url = url('http://www.perl.com/cgi-bin/cpan_mod'); $url->query_form(module => 'DB_File', readme => 1); $content = get($url); =begin original If you're using the POST method, create your own user agent and encode the content appropriately. =end original POST �᥽�åɤ�ȤäƤ���ΤǤ���С���ʬ�ѤΥ���������Ȥ�������� ����ƥ�Ĥ�Ŭ�ڤ˥��󥳡��ɤ��Ƥ��ޤ��� use HTTP::Request::Common qw(POST); use LWP::UserAgent; $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; =head2 How do I decode or create those %-encodings on the web? X X X X X (web��� %-encodings ��ǥ����ɤ��������������ꤹ��ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original Those C<%> encodings handle reserved characters in URIs, as described in RFC 2396, Section 2. This encoding replaces the reserved character with the hexadecimal representation of the character's number from the US-ASCII table. For instance, a colon, C<:>, becomes C<%3A>. =end original ������ C<%> ��沽�� RFC 2396 �� 2 �Ϥ˵��Ҥ���Ƥ��롢 URI �Ȥ���ͽ�󤵤�Ƥ���ʸ���򰷤��ޤ��� ������沽��ͽ��ʸ���򡢤���ʸ�����ֹ�� 16 ��ɽ���� US-ASCII �ơ��֥��Ȥä��֤������ޤ��� �㤨�С������� (C<:>) �� C<%3A> �ˤʤ�ޤ��� =begin original In CGI scripts, you don't have to worry about decoding URIs if you are using C. You shouldn't have to process the URI yourself, either on the way in or the way out. =end original CGI ������ץȤǤϡ�C ��ȤäƤ���ʤ� URL �Υǥ����ɤˤĤ��� ���ˤ���ɬ�פϤ���ޤ��� ���󥳡��ɤˤ��Ƥ�ǥ����ɤˤ��Ƥ⡢URI ��ʬ�ǽ�������ɬ�פϤʤ��Ϥ��Ǥ��� =begin original If you have to encode a string yourself, remember that you should never try to encode an already-composed URI. You need to escape the components separately then put them together. To encode a string, you can use the C module. The C function returns the escaped string: =end original �⤷ʸ�����ʬ�ǥ��󥳡��ɤ���ɬ�פ�����ʤ顢 �褷�Ƥ��Ǥ˹������줿 URI �򥨥󥳡��ɤ���٤��ǤϤʤ����Ȥ� ˺��ʤ��Ǥ��������� ���Ǥ��̡��˥��������פ��ơ����줫�����Ƥ��碌�ޤ��� ʸ����򥨥󥳡��ɤ���ˤϡ�C �⥸�塼�뤬�Ȥ��ޤ��� C �ؿ��ϥ��������פ��줿ʸ������֤��ޤ�: my $original = "Colon : Hash # Percent %"; my $escaped = uri_escape( $original ); print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25' =begin original To decode the string, use the C function: =end original ʸ�����ǥ����ɤ���ˤϡ�C �ؿ���Ȥ��ޤ�: my $unescaped = uri_unescape( $escaped ); print $unescaped; # back to original =begin original If you wanted to do it yourself, you simply need to replace the reserved characters with their encodings. A global substitution is one way to do it: =end original �⤷�����ʬ�Ǥ���ʤ顢ñ��ͽ��ʸ���򥨥󥳡��ɤ��줿ʪ���֤������ޤ��� ���Τ���٤��Ѵ�����ʤ顢�ʲ��Τ褦�ˤ��ޤ�: # encode $string =~ s/([^^A-Za-z0-9\-_.!~*'()])/ sprintf "%%%0x", ord $1 /eg; #decode $string =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg; =head2 How do I redirect to another page? (�̤Υڡ����˥�����쥯�Ȥ���ˤ�?) =begin original 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 "Location:" 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. =end original (���Ȥ�Ʊ�������ФǤ�)������δ����� URL ����ꤷ�Ƥ��������� ����� Parsed Headers ������ץȤȤ��� CGI ���ͤ�������줿��Ĥΰۤʤä� CGI "Location:" �쥹�ݥ󥹤Τ����ΰ�ĤǤ��� ����¾�μ��� (���� URL �ѥ�) �� HTTP ������쥯�Ȥʤ��˥����Фˤ�ä� ����Ū�˲�褵��ޤ��� CGI ���ͤǤϤɤ���ξ��Ǥ����� URL ��ǧ����Ƥ��ޤ��� =begin original Use of C is strongly recommended. This example shows redirection with a complete URL. This redirection is handled by the web browser. =end original C ��Ȥ����Ȥ򶯤������ᤷ�ޤ��� ������Ǥϴ����� URL �ؤΥ�����쥯�Ȥ�Ԥ��ޤ��� ���Υ�����쥯�Ȥ� web �֥饦���ˤ�äư����ޤ��� use CGI qw/:standard/; my $url = 'http://www.cpan.org/'; print redirect($url); =begin original This example shows a redirection with an absolute URLpath. This redirection is handled by the local web server. =end original ������Ǥ����� URL �ѥ��ؤΥ�����쥯�Ȥ�Ԥ��ޤ��� ���Υ�����쥯�Ȥϥ�������� web �����Фˤ�äƹԤ��ޤ��� my $url = '/CPAN/index.html'; print redirect($url); =begin original But if coded directly, it could be as follows (the final "\n" is shown separately, for clarity), using either a complete URL or an absolute URLpath. =end original ��������ľ�ܥ����ǥ��󥰤���ʤ顢������ URL ������ URLpath ��Ȥäơ� �ʲ��Τ褦�ˤʤ�ޤ�(�Ǹ�� "\n" �����β����뤿���ʬ����ɽ�����Ƥ��ޤ�)�� print "Location: $url\n"; # CGI response header print "\n"; # end of headers =head2 How do I put a password on my web pages? (��� web �ڡ����ǥѥ���ɤ����Ϥ���ˤ�?) =begin original 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. =end original ���Ѥ��� Web �����С���ǧ�ڤ�ͭ���ˤ���ˤϡ�Web �����С������ꤹ�뤳�Ȥ� ɬ�פǤ��� web �����Фμ���ˤ�ä�����ϰۤʤ�ޤ� -- apache �� iPlanet �Ȥϰۤʤꡢ �ޤ� IIS �Ȥ�ۤʤ�ޤ��� ����Υ����С��˴ؤ���ܺ٤ˤĤ��Ƥϡ����Υ����С��Υɥ�����Ȥ� �����å����Ƥ��������� =head2 How do I edit my .htpasswd and .htgroup files with Perl? (Perl ��Ȥä� .htpasswd �� .htgroup �Ȥ��ä��ե�������Խ�����ˤ�?) =begin original The C and C 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. C supports files used by the "Basic" and "Digest" authentication schemes. Here's an example: =end original C �⥸�塼��� C �⥸�塼��ϡ� �ե����뤬�ɤΤ褦�˳�Ǽ����Ƥ��뤫�˴ط��ʤ������Υե�������Ф��� ������Ӥ������֥������Ȼظ����󥿡��ե��������󶡤��ޤ��� �ǡ����١����ϥƥ����ȡ�dbm��Berkeley DB�����뤤�� DBI �ߴ��ɥ饤�ФΤ��� �ɤ�ʥǡ����١����Ǥ⤫�ޤ��ޤ��� C �� "Basic" ����� "Digest" ǧ�ڥ�������� �Ȥ���ե�����򥵥ݡ��Ȥ��ޤ��� �ʲ������󤲤ޤ�: use HTTPD::UserAdmin (); HTTPD::UserAdmin ->new(DB => "/foo/.htpasswd") ->add($username => $password); =head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things? (��� CGI ������ץȤ˰��ƶ���⤿�餹�褦�ʤ�Τ򡢥桼�������ե���������ϤǤ��ʤ��褦�ˤ���ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original You can't prevent people from sending your script bad data. Even if you add some client-side checks, people may disable them or bypass them completely. For instance, someone might use a module such as C to access your CGI program. If you want to prevent data that try to use SQL injection or other sorts of attacks (and you should want to), you have to not trust any data that enter your program. =end original �͡���������ץȤ˰����ǡ���������Τ��ɤ����ȤϽ���ޤ��� �㤨���饤�����¦�ǥ����å��򤷤��Ȥ��Ƥ⡢�����̵���ˤ����� �����˲��򤷤���Ǥ��ޤ��� �㤨�С�CGI �ץ������� C �Τ褦�ʥ⥸�塼���Ȥ����⤷��ޤ��� SQL ���󥸥���������Ʊ�ͤμ���ι����Ԥ��褦�ʥǡ������ɤ������Τʤ� (�����Ƥ����餯�����������Ǥ��礦)���ץ����������Ϥ���� �ɤ�ʥǡ����⿮�Ѥ��ʤ��褦�ˤ���ɬ�פ�����ޤ��� =begin original The L documentation has general advice about data security. If you are using the C module, use placeholder to fill in data. If you are running external programs with C or C, use the list forms. There are many other precautions that you should take, too many to list here, and most of them fall under the category of not using any data that you don't intend to use. Trust no one. =end original L ʸ��ˤϥǡ����������ƥ��˴ؤ������Ū�ʽ���������ޤ��� C �⥸�塼���ȤäƤ���ʤ顢�ǡ���������Τ˥ץ졼���ۥ���� �ȤäƤ��������� C �� C �dz����ץ�������¹Ԥ��Ƥ���ʤ顢�ꥹ�ȷ����� �ȤäƤ��������� ����¾�������˽񤭤���ʤ��ۤɤ����դ���٤�¿���λ������դ����ꡢ ���ΤۤȤ�ɤϡ��Ȥ����Ȥ��Ƥ��ʤ��ǡ����ϻȤ�ʤ��Ȥ���ʬ������ƤϤޤ�ޤ��� ï�⿮�Ѥ��ʤ��Ǥ��������� =head2 How do I parse a mail header? (�᡼��Υإå�������Ϥ���ˤ�?) =begin original For a quick-and-dirty solution, try this solution derived from L: =end original ��®�ʲ����ʤ顢L ������������ �ʲ��Τ�������ƤߤƤ�������: $/ = ''; $header = ; $header =~ s/\n\s+/ /g; # merge continuation lines %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header ); =begin original 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 C module from CPAN (part of the C package). =end original ���Τ�����ϡ����Ȥ��м��������Ԥ��٤Ƥ��ݼ餷�褦�Ȥ���Ȥ��ˤ� ���ޤ�����ޤ��� ��괰���ʥ��ץ������� CPAN �ˤ��� C �⥸�塼��� �Ȥ��Ȥ�����ΤǤ�(���Υ⥸�塼��� C �ѥå������ΰ����Ǥ�)�� =head2 How do I decode a CGI form? (CGI �ե������ǥ����ɤ���ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original Use the C 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. =end original Perl ��Ʊ������Ƥ��� C �⥸�塼���Ȥ��ޤ��礦�� ������᤯����ñ�ǡ�ʪ�����������Ԥ��뤳�Ȥ�μ¤ˤ��뤿��� ����äȤ�����Ȥ�Ԥ��ޤ��� GET, POST, HEAD �ꥯ�����ȡ��ޥ���ѡ��ȥե����ࡢʣ���ͥե�����ɡ� ������ʸ����ȥ�å������ܥǥ����Ȥ߹�碌������Ӥ���¾�Ρ� ���ʤ����ͤ��褦�Ȥ�פ�ʤ��褦��¿���λ����򰷤��ޤ��� =begin original It doesn't get much easier: the C module automatically parses the input and makes each value available through the C function. =end original ����ʾ��ñ�ˤϤʤ�ޤ���: C �⥸�塼������Ϥ�ưŪ�˥ѡ������ơ� ���줾����ͤ� C �ؿ����̤������Ѳ�ǽ�ˤ��ޤ��� use CGI qw(:standard); my $total = param( 'price' ) + param( 'shipping' ); my @items = param( 'item' ); # multiple values, same field name =begin original If you want an object-oriented approach, C can do that too. =end original ���֥������Ȼظ��ʼ�ˡ���Ȥ������ʤ顢C �Ϥ��Τ褦�ˤ�Ǥ��ޤ��� use CGI; my $cgi = CGI->new(); my $total = $cgi->param( 'price' ) + $cgi->param( 'shipping' ); my @items = $cgi->param( 'item' ); =begin original You might also try C which is a lightweight version of the same thing. Other CGI::* modules on CPAN might work better for you, too. =end original Ʊ�����Ȥ򤹤�����Ǥ� C ���������⤷��ޤ��� CPAN �ˤ��뤽��¾�� CGI::* �⥸�塼��⤢�ʤ��Τ���ˤ褯Ư���Ǥ��礦�� =begin original Many people try to write their own decoder (or copy one from another program) and then run into one of the many "gotchas" of the task. It's much easier and less hassle to use C. =end original ¿���ο͡�����ʬ�ѤΥǥ�������񤳤��Ȥ��ޤ� (���뤤��¾�Υץ�����फ�� ���ԡ����褦�Ȥ��ޤ�); �����Ƥ��κ�Ȥ�¿���Ρ֥��ġפΰ�Ĥ˽Ф��魯���Ȥ� �ʤ�ޤ��� C ��Ȥ����ȤϤ���ñ�ǡ����ݻ��⾯�ʤ��ʤ�ޤ��� =head2 How do I check a valid mail address? (�᡼�륢�ɥ쥹���������������å�����ˤ�?) =begin original (partly contributed by Aaron Sherman) =end original (������ Aaron Sherman �ˤ�äƴ�£����ޤ���) =begin original This isn't as simple a question as it sounds. There are two parts: =end original ����ϸ����ܤۤ�ñ��ʼ���ǤϤ���ޤ��� �������Ĥ���ʬ����ʤ�ޤ�: =begin original a) How do I verify that an email address is correctly formatted? =end original a) �᡼�륢�ɥ쥹���������������򸡾ڤ���ˤ�? =begin original b) How do I verify that an email address targets a valid recipient? =end original b) �᡼�륢�ɥ쥹�������ʼ����Ԥ��оݤȤ��Ƥ��뤫�򸡾ڤ���ˤ�? =begin original 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 I, but either the C or the C module will do both part I and part I as far as you can in real-time. =end original ���Υ��ɥ쥹�˥᡼������äƤ��줬�Ϥ������ɤ������ǧ���ʤ���� �����˥ѡ��� I ���������ޤ��󤬡�C �� C �Υ⥸�塼��ϡ��ꥢ�륿����ǤǤ���¤�� ���Ȥ��Ф��ƥѡ��� I �ȥѡ��� I ��ξ����Ԥ��ޤ��� =begin original If you want to just check part I 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 I matches the address itself: =end original �⤷���ʤ���ñ�������ɽ���ǥ��ɥ쥹���᡼��إå�ɸ��˽��äƤ��뤫�� ���뤳�Ȥǥѡ��� I ������å��������ʤ顢����������뤳�Ȥˤʤ�ޤ�; �ʤ��ʤ顢RFC-2822 (�ǿ��Υ᡼��إå�ɸ��) �˽�򤷤Ƥʤ�����ɤ� ��ã��ǽ�ʥ��ɥ쥹��¸�ߤ���ɸ��˽�򤷤Ƥ��뤱��ɤ���ã��ǽ�ʥ��ɥ쥹�� ¸�ߤ��뤫��Ǥ��� �������ʲ��Υ����ɤϡ������ȡ��ޤ���ߤζ��򡢤��뤤�Ϥ���¾�λ����٤�� �ʤäƤ������ܼ�Ū�Ǥʤ����Ǥ�ޤ�Ǥ��ʤ���ͭ���� RFC-2822 ���ɥ쥹�� �ޥå��󥰤��ޤ��� ����� I<ñ��> ���ɥ쥹���Ȥ˥ޥå��󥰤��ޤ�: 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 $quotedpair = qr{\\[\x00-\x09\x0B-\x0c\x0e-\x7e]}; my $domain_lit = qr{\[(?:$quotedpair|[\x21-\x5a\x5e-\x7e])*\]}; my $domain = qr{(?:$dot_atom|$domain_lit)}; my $addr_spec = qr{$local\@$domain}; =begin original Just match an address against C 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. =end original �⤷���ɥ쥹�� RFC 2822 ���ͤ˽�򤷤Ƥ��뤫�ɤ����򸫤����ʤ顢ñ�� C �ȥޥå��󥰤����Ƥ��������� �����������Τ褦�������������Υ��ɥ쥹���ºݤ�����θĿͤ��Ϥ� ��������ˡ�ʤΤ������뤤�Ϥ��θĿͤ˴�Ϣ�դ���줿�᡼��ܥå����� �Ϥ��Τ����������Τˤ��뤳�Ȥ��Բ�ǽ�ʤΤǡ������ɤ��Ȥ����ˤĤ��Ƥ� �ȤƤ⿵�Ťˤʤ�ɬ�פ�����ޤ��� =begin original 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. =end original �䤿�����Ǥ�������Υ��ɥХ����ϡ��ĿͤΥ᡼�륢�ɥ쥹������å�����Τ� �ѥ���ɤ��ѹ�����Ȥ���Ʊ���褦�˥桼�����˥��ɥ쥹�� ������Ϥ�����Ȥ�����ΤǤ��� ����ˤ�ä��̾���Ǥ��ְ㤤���ɤ����Ȥ��Ǥ��ޤ��� �������Ϥ��ޥå������ʤ顢�Ŀ�Ū�����ƤΥ�å�������᡼��Ȥ��� ���Υ��ɥ쥹������ޤ��� �⤷��å��������֤äƤ��ơ����줬���ʤ��λؼ��˽��äƤ���ʤ顢 ���줬�ºݤΤ�ΤǤ���Ƚ�ʬ�˲���Ǥ��ޤ��� =begin original 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 "vacation" 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. =end original ��굶¤�Τ��ˤ����̤Τ�����ˡ������å����оݼԤ��Ф��� PIN (Personal ID Number) ��Ϳ����Ȥ�����Τ�����ޤ��� ��ν����Τ���˥��ɥ쥹�� PIN (������Ǥ��뤳�Ȥ�˾�ޤ���)�� ��Ͽ���Ƥ����ΤǤ��� ���ʤ����᡼�������Ȥ��ˡ�������ͤ��Ф������νФ���ץ饤�� PIN ��ޤ��褦�˰��ꤹ��ΤǤ��� ���������줬���Τޤ��֤äƤ����ꡢ���뤤���֤äƤ�����å������� "vacation" ������ץȤ��̤��ƤΤ�ΤǤ��äƤ⡢���Τޤ� PIN �� �ޤޤ�Ƥ��ޤ��ޤ��� �Ǥ����顢�����ʤ�����ϥ᡼�������Ȥ����ֻ��ˤ�ʸ����ս�ˤ���Ȥ��� �Ʒ���Ф���­�������������Ԥ��ʤɤ��� PIN ���ѷ�������Τ�ޤ���֤��褦�˰��ꤹ��Ȥ�����ˡ�Ǥ��� =head2 How do I decode a MIME/BASE64 string? (MIME/BASE64 ʸ����Υǥ����ɤ�Ԥ��ˤ�?) =begin original The C package (available from CPAN) handles this as well as the MIME/QP encoding. Decoding BASE64 becomes as simple as: =end original C �ѥå�����(CPAN �������ǽ�Ǥ�)�Ϥ�������ȡ� MIME/QP ���󥳡��ǥ��󥰤��갷���ޤ��� BASE64 �Υǥ����ɤϰʲ��Τ褦��ñ��Ǥ�: use MIME::Base64; $decoded = decode_base64($encoded); =begin original The C package (available from CPAN) supports extraction with decoding of BASE64 encoded attachments and content directly from email messages. =end original C �ѥå����� (CPAN �ˤ���ޤ�) �� BASE64 ���󥳡��ɤ��줿 ź�եե��������ʸ��᡼��Υ�å���������ľ����ФǤ��ޤ��� =begin original If the string to decode is short (less than 84 bytes long) a more direct approach is to use the C function's "u" format after minor transliterations: =end original �⤷�ǥ����ɤ�����ʸ����û��(84 ʸ���ʲ�)�ξ�硢���ľ��Ū�ʤ�����ϡ� ����äȤ����Ѵ��򤷤���� C �ؿ��� "u" �ե����ޥåȤ� �Ȥ��Ȥ�����ΤǤ�: 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 =head2 How do I return the user's mail address? (�桼�����Υ᡼�륢�ɥ쥹���֤��ˤ�?) =begin original On systems that support getpwuid, the C<< $< >> variable, and the C module (which is part of the standard perl distribution), you can probably try using something like this: =end original getpwuid �򥵥ݡ��Ȥ��Ƥ��륷���ƥ�Ǥ���С�C<< $< >> �Ȥ����ѿ��� C �⥸�塼��(ɸ��� perl ���ۥ��åȤΰ����Ǥ�)��Ȥä� �ʲ��Τ褦�ʤ��Ȥ����Ǥ��礦�� use Sys::Hostname; $address = sprintf('%s@%s', scalar getpwuid($<), hostname); =begin original 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. =end original ��ҤΥ᡼�륢�ɥ쥹�˴ؤ���ݥꥷ���������줬�������륢�ɥ쥹�� ���β�ҤΥ᡼�륷���ƥब�����դ��ʤ���ΤǤ����ǽ��������ޤ��� �Ǥ����顢�桼�����ˡ����Υ桼�����Υ᡼�륢�ɥ쥹��Ҥͤ�٤��Ǥ��礦�� ����˲ä���Perl ��ư������ƤΥ����ƥ�� ���ξ���(UNIX ��Ʊ���褦��)������櫓�ǤϤ���ޤ��� =begin original The C module from CPAN (part of the C package) provides a C 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. =end original CPAN �ˤ��� C �⥸�塼�� (C �ѥå������ΰ����Ǥ�)�� �᡼�륢�ɥ쥹�����Υ桼�����Τ�ΤǤ��뤫�ɤ�����Τ���褦�Ȥ��� C �Ȥ����ؿ����󶡤��Ƥ��ޤ��� ����Ͼ���㼨������������⸭�����⥸�塼�뤬���󥹥ȡ��뤵�줿�Ȥ��� �����Ȥ��ޤ���������Ǥ��������ʤ���ǽ��������ޤ��� �����֤��ޤ�������������ˡ�ϥ桼�����˿Ҥͤ뤳�ȡ��Ȥ����Τ��ۤȤ�ɤǤ��� =head2 How do I send mail? (�᡼�������ˤ�?) =begin original Use the C program directly: =end original C �ץ�������ľ�ܻȤ��ޤ�: open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; From: User Originating Mail To: Final Destination Subject: A relevant subject line 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"; =begin original The B<-oi> option prevents C from interpreting a line consisting of a single dot as "end of message". The B<-t> option says to use the headers to decide who to send the message to, and B<-odq> 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. =end original B<-oi> ���ץ����� C ���ɥåȤ����ιԤ�ȥ�å������ν����ɤ� �ߤʤ��ʤ��褦�ˤ��뤿��Υ��ץ����Ǥ��� B<-t>���ץ����ϥ�å�������ï�����뤫����뤫�Τ���� �إå�����Ȥ����Ȥ�ؼ�����B<-odq> ���ץ�����å������� ���塼������뤳�Ȥ�ؼ����ޤ��� �Ǹ�Υ��ץ����ΰ�̣�ϡ����ʤ��Υ�å������������ˤ���������ʤ����Ȥ� ��̣���ޤ��� �Ǥ����顢�������������������ΤǤ���Ф��Υ��ץ�����������Ƥ��������� =begin original Alternate, less convenient approaches include calling C (sometimes called C) directly or simply opening up port 25 have having an intimate conversation between just you and the remote SMTP daemon, probably C. =end original ���뤤�ϡ�ľ�� C (C �ȸƤФ�뤳�Ȥ⤢��ޤ�)��ƤӤ������ꡢ ñ��� 25 �֥ݡ��Ȥ�Ȥäƥ�⡼�Ȥ� SMTP �ǡ����(¿ʬ C �Ǥ��礦) �Ȥδ֤Ǿܺ٤��̿���Ԥ��Ȥ��ä����ޤ������Ǥʤ���ˡ�⤢��ޤ��� =begin original Or you might be able use the CPAN module C: =end original ���뤤�� CPAN �ˤ���⥸�塼�� C ���Ȥ��뤫�⤷��ޤ���: use Mail::Mailer; $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(); =begin original The C module uses C which is less Unix-centric than C, but less reliable. Avoid raw SMTP commands. There are many reasons to use a mail transport agent like C. These include queuing, MX records, and security. =end original C �⥸�塼��� C ��� UNIX Ū�ǤϤʤ� C ��ȤäƤ��ޤ��������������㤤�Ǥ��� ���� SMTP ���ޥ�ɤ�̵�뤷�ޤ��� C �Τ褦�� mail transport agent ��Ȥ���ͳ�Ϥ������󤢤�ޤ��� ������ˤϥ��塼���󥰤�ޤޤ�ޤ�����MX �쥳���ɤ䥻�����ƥ��� ���ä���Τ��ޤޤ�ޤ��� =head2 How do I use MIME to make an attachment to a mail message? (�᡼���å�������ź�դ��뤿��ˤɤ���ä� MIME ��Ȥ��Ф����Ǥ���?) =begin original This answer is extracted directly from the C documentation. Create a multipart message (i.e., one with attachments). =end original ���β����� C �Υɥ�����Ȥ���ľ�ܻ��äƤ�����ΤǤ��� �ޥ���ѡ��ȥ�å�����(�Ĥޤ� ź�դĤ��Υ�å�����) ����ޤ��� use MIME::Lite; ### 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' ); ### 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' ); $text = $msg->as_string; =begin original C also includes a method for sending these things. =end original C �Ϥޤ������Τ�Τ����뤿��Υ᥽�åɤ�ޤߤޤ��� $msg->send; =begin original This defaults to using L but can be customized to use SMTP via L. =end original ����ϥǥե���ȤǤ� L ��Ȥ��ޤ����� L ��ͳ�� SMTP ��Ȥ��褦�˥������ޥ����Ǥ��ޤ��� =head2 How do I read mail? (�᡼����ɤ߽Ф��ˤ�?) =begin original While you could use the C module from CPAN (part of the C package) or the C module from CPAN (part of the C package), often a module is overkill. Here's a mail sorter. =end original CPAN �ˤ��� C �⥸�塼��(C �ѥå������ΰ����Ǥ�)�� C �⥸�塼��(����� C �ѥå������ΰ����Ǥ�)�� �Ȥ��ޤ������⥸�塼���Ȥ��ΤϤ�ꤹ�����⤷��ޤ��� �ʲ��˥᡼��򥽡��Ȥ�����ˡ�򼨤��ޤ��� #!/usr/bin/perl 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]; } =begin original Or more succinctly, =end original ���뤤�Ϥ�äȴʷ��: #!/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) ] } =head2 How do I find out my hostname, domainname, or IP address? X (��Υۥ���̾/�ɥᥤ��̾/IP ���ɥ쥹�򸫤Ĥ���ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original The C 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. =end original perl5.7.3 ����ɸ�����ۤ���Ƥ��� C �⥸�塼���Ȥ��ȡ� ���������ɥᥤ��̾ (FQDN)���ۥ���̾���ɥᥤ��̾�������ޤ��� use Net::Domain qw(hostname hostfqdn hostdomain); my $host = hostfqdn(); =begin original The C module, included in the standard distribution since perl5.6, can also get the hostname. =end original perl5.6 ����ɸ�����ۤ���Ƥ��� C �⥸�塼��Ǥ� �ۥ���̾�������ޤ��� use Sys::Hostname; $host = hostname(); =begin original To get the IP address, you can use the C 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 C function from the C module, which also comes with perl. =end original IP ���ɥ쥹������ˤϡ�̾��������ͤ��Ѵ����뤿��� C �Ȥ߹��ߴؿ����Ȥ��ޤ��� ���ͤ򡢤ۤȤ�ɤοͤ����ꤷ�Ƥ���ԥꥪ���դ��η� (a.b.c.d) ���Ѵ�����ˤϡ� ɸ�����ۤ���Ƥ��� C �⥸�塼��� C �ؿ���Ȥ��ޤ��� use Socket; my $address = inet_ntoa( scalar gethostbyname( $host || 'localhost' ) ); =head2 How do I fetch a news article or the active newsgroups? (�˥塼���ε����䥢���ƥ��֤ʥ˥塼�����롼�פ��������ˤ�?) =begin original Use the C or C modules, both available from CPAN. This can make tasks like fetching the newsgroup list as simple as =end original C �⥸�塼�뤫 C �⥸�塼��Τ����줫��Ȥ��ޤ��� ������ξ���Ȥ� CPAN ���������ǽ�Ǥ��� �����ϰʲ��Τ褦�˴�ñ�˥˥塼�����롼�פΥꥹ�Ȥ��������褦�� ��Ȥ��Ǥ��ޤ��� perl -MNews::NNTPClient -e 'print News::NNTPClient->new->list("newsgroups")' =head2 How do I fetch/put an FTP file? (FTP �ե����������������/���åץ����ɤ���ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original The C family of modules (available on CPAN as the libwww-perl distribution) can work with FTP just like it can with many other protocols. C makes it quite easy to fetch a file: =end original C �⥸�塼��ե��ߥ꡼ (CPAN �� libwww-perl ���ۤȤ������Ѳ�ǽ�Ǥ�) �� FTP �򤽤�¾�Υץ��ȥ����Ʊ�ͤ˰����ޤ��� C �ϥե���������������ɤ���Τ�ȤƤ��ñ�ˤ��ޤ�: use LWP::Simple; my $data = get( 'ftp://some.ftp.site/some/file.txt' ); =begin original If you want more direct or low-level control of the FTP process, you can use the C module (in the Standard Library since Perl 5.8). It's documentation has examples showing you just how to do that. =end original FTP ��������ľ��Ū�ˡ����뤤�����٥�����椬�������ʤ顢(Perl 5.8 �ʹ� ɸ��饤�֥������äƤ���) C �⥸�塼�뤬�Ȥ��ޤ��� ����ʸ��ˤϤ����Ԥ���ˡ�򼨤�������㤬�ܤäƤ��ޤ��� =head2 How can I do RPC in Perl? (Perl �� RPC ��Ԥ��ˤ�?) =begin original (contributed by brian d foy) =end original (brian d foy �ˤ�äƴ�£����ޤ���) =begin original Use one of the RPC modules you can find on CPAN ( http://search.cpan.org/search?query=RPC&mode=all ). =end original CPAN ( http://search.cpan.org/search?query=RPC&mode=all ) �Ǹ��դ��� RFC �⥸�塼��ΰ�Ĥ�Ȥ��ޤ��礦�� =head1 AUTHOR AND COPYRIGHT Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and other authors as noted. All rights reserved. This documentation is free; you can redistribute it and/or modify it under the same terms as Perl itself. 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. =begin meta Translate: ��¼ ���� Update: SHIRAKATA Kentaro (5.6.1-) Status: completed =end meta