summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/pod/perlfaq9.pod
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/perl5/pod/perlfaq9.pod')
-rw-r--r--contrib/perl5/pod/perlfaq9.pod107
1 files changed, 54 insertions, 53 deletions
diff --git a/contrib/perl5/pod/perlfaq9.pod b/contrib/perl5/pod/perlfaq9.pod
index 6536064..16a803c 100644
--- a/contrib/perl5/pod/perlfaq9.pod
+++ b/contrib/perl5/pod/perlfaq9.pod
@@ -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,11 +76,13 @@ 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. 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.
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
+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 comment may be present. Plus folks forget to convert
entities, like C<&lt;> for example.
@@ -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?
@@ -147,7 +148,7 @@ the same as the startform() method.
=head2 How do I make a pop-up menu in HTML?
-Use the B<E<lt>SELECTE<gt>> and B<E<lt>OPTIONE<gt>> tags. The CGI.pm
+Use the B<< <SELECT> >> and B<< <OPTION> >> tags. The CGI.pm
module (available from CPAN) supports this widget, as well as many
others, including some that it cleverly synthesizes on its own.
@@ -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;
@@ -168,12 +170,12 @@ do this. They work through proxies, and don't require lynx:
# or print HTML from a URL
use LWP::Simple;
- getprint "http://www.sn.no/libwww-perl/";
+ getprint "http://www.linpro.no/lwp/";
# 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/");
@@ -213,11 +215,11 @@ Here's an example of decoding:
$string =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge;
Encoding is a bit harder, because you can't just blindly change
-all the non-alphanumeric characters (C<\W>) into their hex escapes.
+all the non-alphanumunder character (C<\W>) into their hex escapes.
It's important that characters with special meaning like C</> and C<?>
I<not> be translated. Probably the easiest way to get this right is
to avoid reinventing the wheel and just use the URI::Escape module,
-which is part of the libwww-perl package (LWP) available from CPAN.
+available from CPAN.
=head2 How do I redirect to another page?
@@ -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
@@ -382,12 +396,12 @@ format after minor transliterations:
=head2 How do I return the user's mail address?
-On systems that support getpwuid, the $E<lt> variable and the
+On systems that support getpwuid, the $< variable and the
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
@@ -541,7 +543,7 @@ All rights reserved.
When included as part of the Standard Version of Perl, or as part of
its complete documentation whether printed or otherwise, this work
-may be distributed only under the terms of Perl's Artistic Licence.
+may be distributed only under the terms of Perl's Artistic License.
Any distribution of this file or derivatives thereof I<outside>
of that package require that special arrangements be made with
copyright holder.
@@ -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.
-
OpenPOWER on IntegriCloud