better documentation for goto &NAME (from M. J. T. Guy)
[p5sagit/p5-mst-13.2.git] / pod / perlfaq9.pod
index 46c487b..7fc0cdc 100644 (file)
@@ -1,6 +1,6 @@
 =head1 NAME
 
-perlfaq9 - Networking ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
+perlfaq9 - Networking ($Revision: 1.26 $, $Date: 1999/05/23 16:08:30 $)
 
 =head1 DESCRIPTION
 
@@ -76,8 +76,10 @@ stamp prepended.
 
 =head2 How do I remove HTML from a string?
 
-The most correct way (albeit not the fastest) is to use HTML::Parse
-from CPAN (part of the HTML-Tree package on CPAN).
+The most correct way (albeit not the fastest) is to use HTML::Parser
+from CPAN (part of the HTML-Tree package on CPAN).  Another 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.
 
 Many folks attempt a simple-minded regular expression approach, like
 C<s/E<lt>.*?E<gt>//g>, but that fails in many cases because the tags
@@ -100,7 +102,7 @@ a solution:
 
     <IMG SRC = "foo.gif" ALT = "A > B">
 
-    <IMG SRC = "foo.gif" 
+    <IMG SRC = "foo.gif"
         ALT = "A > B">
 
     <!-- <A comment> -->
@@ -131,12 +133,11 @@ A quick but imperfect approach is
     }gsix;
 
 This version does not adjust relative URLs, understand alternate
-bases, deal with HTML comments, deal with HREF and NAME attributes in
-the same tag, or accept URLs themselves as arguments.  It also runs
-about 100x faster than a more "complete" solution using the LWP suite
-of modules, such as the
-http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz
-program.
+bases, deal with HTML comments, deal with HREF and NAME attributes
+in the same tag, understand extra qualifiers like TARGET, or accept
+URLs themselves as arguments.  It also runs about 100x faster than a
+more "complete" solution using the LWP suite of modules, such as the
+http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz program.
 
 =head2 How do I download a file from the user's machine?  How do I open a file on another machine?
 
@@ -159,8 +160,9 @@ on your system, is this:
     $html_code = `lynx -source $url`;
     $text_data = `lynx -dump $url`;
 
-The libwww-perl (LWP) modules from CPAN provide a more powerful way to
-do this.  They work through proxies, and don't require lynx:
+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:
 
     # simplest version
     use LWP::Simple;
@@ -173,7 +175,7 @@ do this.  They work through proxies, and don't require lynx:
     # or print ASCII from HTML from a URL
     # also need HTML-Tree package from CPAN
     use LWP::Simple;
-    use HTML::Parse;
+    use HTML::Parser;
     use HTML::FormatText;
     my ($html, $ascii);
     $html = get("http://www.perl.com/");
@@ -236,9 +238,21 @@ because of "optimizations" that servers do.
     print "Location: $url\n\n";
     exit;
 
-To be correct to the spec, each of those C<"\n">
-should really each be C<"\015\012">, but unless you're
-stuck on MacOS, you probably won't notice.
+To target a particular frame in a frameset, include the "Window-target:"
+in the header.
+
+    print <<EOF;
+    Location: http://www.domain.com/newpage
+    Window-target: <FrameName>
+
+    EOF
+
+To be correct to the spec, each of those virtual newlines should really be
+physical C<"\015\012"> sequences by the time you hit the client browser.
+Except for NPH scripts, though, that local newline should get translated
+by your server into standard form, so you shouldn't have a problem
+here, even if you are stuck on MacOS.  Everybody else probably won't
+even notice.
 
 =head2 How do I put a password on my web pages?
 
@@ -329,7 +343,7 @@ RFC-822 (the mail header standard) compliant, and addresses that aren't
 deliverable which are compliant.
 
 Many are tempted to try to eliminate many frequently-invalid
-mail addresses with a simple regexp, such as
+mail addresses with a simple regex, such as
 C</^[\w.-]+\@([\w.-]\.)+\w+$/>.  It's a very bad idea.  However,
 this also throws out many valid ones, and says nothing about
 potential deliverability, so is not suggested.  Instead, see
@@ -387,7 +401,7 @@ Sys::Hostname module (which is part of the standard perl distribution),
 you can probably try using something like this:
 
     use Sys::Hostname;
-    $address = sprintf('%s@%s', getpwuid($<), hostname);
+    $address = sprintf('%s@%s', scalar getpwuid($<), hostname);
 
 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
@@ -423,7 +437,12 @@ 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.
 
-Or use the CPAN module Mail::Mailer:
+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.
+
+Or you might be able use the CPAN module Mail::Mailer:
 
     use Mail::Mailer;
 
@@ -438,34 +457,17 @@ Or use the CPAN module Mail::Mailer:
 
 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 
+are many reasons to use a mail transport agent like sendmail.  These
 include queueing, MX records, and security.
 
 =head2 How do I read mail?
 
-Use the Mail::Folder module from CPAN (part of the MailFolder package) or
-the Mail::Internet module from CPAN (also part of the MailTools package).
-
-   # sending mail
-    use Mail::Internet;
-    use Mail::Header;
-    # say which mail host to use
-    $ENV{SMTPHOSTS} = 'mail.frii.com';
-    # create headers
-    $header = new Mail::Header;
-    $header->add('From', 'gnat@frii.com');
-    $header->add('Subject', 'Testing');
-    $header->add('To', 'gnat@frii.com');
-    # create body
-    $body = 'This is a test, ignore';
-    # create mail object
-    $mail = new Mail::Internet(undef, Header => $header, Body => \[$body]);
-    # send it
-    $mail->smtpsend or die;
-
-Often a module is overkill, though.  Here's a mail sorter.
-
-    #!/usr/bin/perl 
+While you could use the Mail::Folder module from CPAN (part of the
+MailFolder package) or the Mail::Internet module from CPAN (also part
+of the MailTools package), often a module is overkill, though.  Here's a
+mail sorter.
+
+    #!/usr/bin/perl
     # bysub1 - simple sort by subject
     my(@msgs, @sub);
     my $msgno = -1;
@@ -476,12 +478,12 @@ Often a module is overkill, though.  Here's a mail sorter.
             $sub[++$msgno] = lc($1) || '';
         }
         $msgs[$msgno] .= $_;
-    } 
+    }
     for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) {
         print $msgs[$i];
     }
 
-Or more succinctly, 
+Or more succinctly,
 
     #!/usr/bin/perl -n00
     # bysub2 - awkish sort-by-subject
@@ -551,4 +553,3 @@ 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.
-