This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Removed unnecessary pointers checks
[perl5.git] / pod / perlfaq9.pod
index 1a40c3b..f017a40 100644 (file)
@@ -1,6 +1,6 @@
 =head1 NAME
 
-perlfaq9 - Networking ($Revision: 1.21 $, $Date: 2005/04/22 19:04:48 $)
+perlfaq9 - Networking ($Revision: 3606 $)
 
 =head1 DESCRIPTION
 
@@ -253,19 +253,18 @@ the content appropriately.
 
 =head2 How do I decode or create those %-encodings on the web?
 
-
 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.
 
-
 The best source of detailed information on URI encoding is RFC 2396.
 Basically, the following substitutions do it:
 
     s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg;   # encode
 
-    s/%([A-Fa-f\d]{2})/chr hex $1/eg;            # decode
+    s/%([A-Fa-f\d]{2})/chr hex $1/eg;                # decode
+       s/%([[:xdigit:]]{2})/chr hex $1/eg;          # same thing
 
 However, you should only apply them to individual URI components, not
 the entire URI, otherwise you'll lose information and generally mess
@@ -322,7 +321,7 @@ 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
-`Basic' and `Digest' authentication schemes.  Here's an example:
+"Basic" and "Digest" authentication schemes.  Here's an example:
 
     use HTTPD::UserAdmin ();
     HTTPD::UserAdmin
@@ -366,9 +365,9 @@ C<param()> function.
 
        use CGI qw(:standard);
 
-       my $total = param( "price" ) + param( "shipping" );
+       my $total = param( 'price' ) + param( 'shipping' );
 
-       my @items = param( "item ); # multiple values, same field name
+       my @items = param( 'item' ); # multiple values, same field name
 
 If you want an object-oriented approach, CGI.pm can do that too.
 
@@ -376,9 +375,9 @@ If you want an object-oriented approach, CGI.pm can do that too.
 
        my $cgi = CGI->new();
 
-       my $total = $cgi->param( "price" ) + $cgi->param( "shipping" );
+       my $total = $cgi->param( 'price' ) + $cgi->param( 'shipping' );
 
-       my @items = $cgi->param( "item" );
+       my @items = $cgi->param( 'item' );
 
 You might also try CGI::Minimal which is a lightweight version
 of the same thing.  Other CGI::* modules on CPAN might work better
@@ -439,7 +438,7 @@ 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
+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.
 
@@ -596,29 +595,37 @@ Or more succinctly,
     $msg[$msgno] .= $_;
     END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] }
 
-=head2 How do I find out my hostname/domainname/IP address?
+=head2 How do I find out my hostname, domainname, or IP address?
+X<hostname, domainname, IP address, host, domain, hostfqdn, inet_ntoa,
+gethostbyname, Socket, Net::Domain, Sys::Hostname>
 
-The normal way to find your own hostname is to call the C<`hostname`>
-program.  While sometimes expedient, this has some problems, such as
-not knowing whether you've got the canonical name or not.  It's one of
-those tradeoffs of convenience versus portability.
+(contributed by brian d foy)
 
-The Sys::Hostname module (part of the standard perl distribution) will
-give you the hostname after which you can find out the IP address
-(assuming you have working DNS) with a gethostbyname() call.
+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.
 
-    use Socket;
-    use Sys::Hostname;
-    my $host = hostname();
-    my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
+       use Net::Domain qw(hostname hostfqdn hostdomain);
+
+       my $host = hostfqdn();
+
+The C<Sys::Hostname> module, included in the standard distribution since
+perl5.6, can also get the hostname.
+
+       use Sys::Hostname;
 
-Probably the simplest way to learn your DNS domain name is to grok
-it out of /etc/resolv.conf, at least under Unix.  Of course, this
-assumes several things about your resolv.conf configuration, including
-that it exists.
+       $host = hostname();
 
-(We still need a good DNS domain name-learning method for non-Unix
-systems.)
+To get the IP address, you can use the C<gethostbyname> 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<inet_ntoa> function
+from the <Socket> module, which also comes with perl.
+
+    use Socket;
+
+    my $address = inet_ntoa(
+       scalar gethostbyname( $host || 'localhost' )
+       );
 
 =head2 How do I fetch a news article or the active newsgroups?
 
@@ -635,14 +642,22 @@ available from CPAN) is more complex but can put as well as fetch.
 
 =head2 How can I do RPC in Perl?
 
-A DCE::RPC module is being developed (but is not yet available) and
-will be released as part of the DCE-Perl package (available from
-CPAN).  The rpcgen suite, available from CPAN/authors/id/JAKE/, is
-an RPC stub generator and includes an RPC::ONC module.
+(Contributed by brian d foy)
+
+Use one of the RPC modules you can find on CPAN (
+http://search.cpan.org/search?query=RPC&mode=all ).
+
+=head1 REVISION
+
+Revision: $Revision: 3606 $
+
+Date: $Date: 2006-03-06 12:05:47 +0100 (lun, 06 mar 2006) $
+
+See L<perlfaq> for source control details and availability.
 
 =head1 AUTHOR AND COPYRIGHT
 
-Copyright (c) 1997-2005 Tom Christiansen, Nathan Torkington, and
+Copyright (c) 1997-2006 Tom Christiansen, Nathan Torkington, and
 other authors as noted. All rights reserved.
 
 This documentation is free; you can redistribute it and/or modify it