X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq9.pod;h=ce0cf072419da3f6825e798bfbb9c5a9a7bfb935;hb=9d6c7f2eccef26a6d6eb46a8192949a88c6aaf8f;hp=577d15115bffb5abf8a2897962edfdbdd21322e6;hpb=9e72e4c611b0297cb770c791d72e9d74b901d604;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq9.pod b/pod/perlfaq9.pod index 577d151..ce0cf07 100644 --- a/pod/perlfaq9.pod +++ b/pod/perlfaq9.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq9 - Networking ($Revision: 1.24 $, $Date: 2005/10/13 19:43:13 $) +perlfaq9 - Networking =head1 DESCRIPTION @@ -65,7 +65,6 @@ listed in the CGI Meta FAQ: http://www.perl.org/CGI_MetaFAQ.html - =head2 How can I get better error messages from a CGI program? Use the CGI::Carp module. It replaces C and C, plus the @@ -73,25 +72,25 @@ normal Carp modules C, C, and C functions with more verbose and safer versions. It still sends them to the normal server error log. - use CGI::Carp; - warn "This is a complaint"; - die "But this one is serious"; + use CGI::Carp; + warn "This is a complaint"; + die "But this one is serious"; 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: - 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 { + use CGI::Carp qw(carpout); + open(LOG, ">>/var/local/cgi-logs/mycgi-log") + or die "Unable to append to mycgi-log: $!\n"; + carpout(*LOG); + } 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. - use CGI::Carp qw(fatalsToBrowser); - die "Bad error here"; + use CGI::Carp qw(fatalsToBrowser); + die "Bad error here"; 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. @@ -114,8 +113,8 @@ entities--like C<<> for example. Here's one "simple-minded" approach, that works for most files: - #!/usr/bin/perl -p0777 - s/<(?:[^>'"]*|(['"]).*?\1)*>//gs + #!/usr/bin/perl -p0777 + s/<(?:[^>'"]*|(['"]).*?\1)*>//gs If you want a more complete solution, see the 3-stage striphtml program in @@ -125,25 +124,25 @@ http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz Here are some tricky cases that you should think about when picking a solution: - A > B + A > B - A > B - + - + - <# Just data #> + <# Just data #> - >>>>>>>>>>> ]]> + >>>>>>>>>>> ]]> If HTML comments include other tags, those solutions would also break on text like this: - + =head2 How do I extract URLs? @@ -163,14 +162,13 @@ 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. - #!/usr/bin/perl -n00 - # qxurl - tchrist@perl.com - print "$2\n" while m{ - < \s* - A \s+ HREF \s* = \s* (["']) (.*?) \1 - \s* > - }gsix; - + #!/usr/bin/perl -n00 + # qxurl - tchrist@perl.com + print "$2\n" while m{ + < \s* + A \s+ HREF \s* = \s* (["']) (.*?) \1 + \s* > + }gsix; =head2 How do I download a file from the user's machine? How do I open a file on another machine? @@ -186,43 +184,50 @@ method. See the section in the CGI.pm documentation on file uploads for code examples and details. -=head2 How do I make a pop-up menu in HTML? +=head2 How do I make an HTML pop-up menu with Perl? + +(contributed by brian d foy) + +The CGI.pm module (which comes with Perl) has functions to create +the HTML form widgets. See the CGI.pm documentation for more +examples. -Use the B<<