diff options
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perldiag.pod | 31 | ||||
-rw-r--r-- | pod/perlfaq.pod | 7 | ||||
-rw-r--r-- | pod/perlfaq1.pod | 13 | ||||
-rw-r--r-- | pod/perlfaq3.pod | 8 | ||||
-rw-r--r-- | pod/perlfaq4.pod | 5 | ||||
-rw-r--r-- | pod/perlfaq5.pod | 5 | ||||
-rw-r--r-- | pod/perlfaq6.pod | 32 | ||||
-rw-r--r-- | pod/perlfaq7.pod | 6 | ||||
-rw-r--r-- | pod/perlfaq8.pod | 389 | ||||
-rw-r--r-- | pod/perltoc.pod | 97 |
10 files changed, 534 insertions, 59 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod index a4a897c64b..5ee141e512 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -890,6 +890,12 @@ times than it has returned. This probably indicates an infinite recursion, unless you're writing strange benchmark programs, in which case it indicates something else. +=item Delimiter for here document is too long + +(F) In a here document construct like C<E<lt>E<lt>FOO>, the label +C<FOO> is too long for Perl to handle. You have to be seriously +twisted to write code that triggers this error. + =item Did you mean &%s instead? (W) You probably referred to an imported subroutine &FOO as $FOO or some such. @@ -949,6 +955,13 @@ single form when it must operate on them directly. Either you've passed an invalid file specification to Perl, or you've found a case the conversion routines don't handle. Drat. +=item Excessively long <> operator + +(F) The contents of a <> operator may not exceed the maximum size of a +Perl identifier. If you're just trying to glob a long list of +filenames, try using the glob() operator, or put the filenames into a +variable and glob that. + =item Execution of %s aborted due to compilation errors (F) The final summary message when a Perl compilation fails. @@ -1101,9 +1114,9 @@ is now heavily deprecated. =item Identifier too long (F) Perl limits identifiers (names for variables, functions, etc.) to -252 characters for simple names, somewhat more for compound names (like -C<$A::B>). You've exceeded Perl's limits. Future versions of Perl are -likely to eliminate these arbitrary limitations. +about 250 characters for simple names, and somewhat more for compound +names (like C<$A::B>). You've exceeded Perl's limits. Future +versions of Perl are likely to eliminate these arbitrary limitations. =item Ill-formed logical name |%s| in prime_env_iter @@ -1581,6 +1594,13 @@ supplied it an uninitialized value. See L<perlform>. (P) The internal pattern matching routines are out of their gourd. +=item Number too long + +(F) Perl limits the representation of decimal numbers in programs to about +about 250 characters. You've exceeded that length. Future versions of +Perl are likely to eliminate this arbitrary limitation. In the meantime, +try using scientific notation (e.g. "1e6" instead of "1_000_000"). + =item Odd number of elements in hash list (S) You specified an odd number of elements to a hash list, which is odd, @@ -2221,6 +2241,11 @@ or "msg". See L<perlfunc/semctl>, for example. (W) The filehandle you're writing to got itself closed sometime before now. Check your logic flow. +=item Target of goto is too deeply nested + +(F) You tried to use C<goto> to reach a label that was too deeply +nested for Perl to reach. Perl is doing you a favor by refusing. + =item tell() on unopened file (W) You tried to use the tell() function on a filehandle that was either diff --git a/pod/perlfaq.pod b/pod/perlfaq.pod index 95a4a5c7f5..2213a0f2f0 100644 --- a/pod/perlfaq.pod +++ b/pod/perlfaq.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq - frequently asked questions about Perl ($Date: 1997/04/23 18:11:06 $) +perlfaq - frequently asked questions about Perl ($Date: 1997/04/24 22:46:06 $) =head1 DESCRIPTION @@ -124,6 +124,11 @@ in respect of this information or its use. =over 4 +=item 24/April/97 + +Style and whitespace changes from Chip, new question on reading one +character at a time from a terminal using POSIX from Tom. + =item 23/April/97 Added http://www.oasis.leo.org/perl/ to L<perlfaq2>. Style fix to diff --git a/pod/perlfaq1.pod b/pod/perlfaq1.pod index 6463a98061..6af40ae129 100644 --- a/pod/perlfaq1.pod +++ b/pod/perlfaq1.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq1 - General Questions About Perl ($Revision: 1.11 $, $Date: 1997/03/19 17:23:09 $) +perlfaq1 - General Questions About Perl ($Revision: 1.12 $, $Date: 1997/04/24 22:43:34 $) =head1 DESCRIPTION @@ -190,11 +190,12 @@ In "standard terminology" a I<program> has been compiled to physical machine code once, and can then be be run multiple times, whereas a I<script> must be translated by a program each time it's used. Perl programs, however, are usually neither strictly compiled nor strictly -interpreted. They can be compiled to a byte code form (something of a Perl -virtual machine) or to completely different languages, like C or assembly -language. You can't tell just by looking whether the source is destined -for a pure interpreter, a parse-tree interpreter, a byte code interpreter, -or a native-code compiler, so it's hard to give a definitive answer here. +interpreted. They can be compiled to a byte code form (something of a +Perl virtual machine) or to completely different languages, like C or +assembly language. You can't tell just by looking whether the source +is destined for a pure interpreter, a parse-tree interpreter, a byte +code interpreter, or a native-code compiler, so it's hard to give a +definitive answer here. =head2 What is a JAPH? diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod index 7489e98a47..c1818109e4 100644 --- a/pod/perlfaq3.pod +++ b/pod/perlfaq3.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq3 - Programming Tools ($Revision: 1.21 $, $Date: 1997/04/23 18:04:23 $) +perlfaq3 - Programming Tools ($Revision: 1.22 $, $Date: 1997/04/24 22:43:42 $) =head1 DESCRIPTION @@ -285,9 +285,9 @@ source. Security through obscurity, the name for hiding your bugs instead of fixing them, is little security indeed. You can try using encryption via source filters (Filter::* from CPAN). -But crackers might be able to decrypt it. You can try using the -byte code compiler and interpreter described below, but crackers might -be able to de-compile it. You can try using the native-code compiler +But crackers might be able to decrypt it. You can try using the byte +code compiler and interpreter described below, but crackers might be +able to de-compile it. You can try using the native-code compiler described below, but crackers might be able to disassemble it. These pose varying degrees of difficulty to people wanting to get at your code, but none can definitively conceal it (this is true of every diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 7c57d58d7d..bcf03990bc 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.18 $, $Date: 1997/04/23 18:04:37 $) +perlfaq4 - Data Manipulation ($Revision: 1.19 $, $Date: 1997/04/24 22:43:57 $) =head1 DESCRIPTION @@ -1019,8 +1019,7 @@ Normally, merely accessing a key's value for a nonexistent key does I<not> cause that key to be forever there. This is different than awk's behavior. -=head2 How can I make the Perl equivalent of a C structure/C++ class/hash -or array of hashes or arrays? +=head2 How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays? Use references (documented in L<perlref>). Examples of complex data structures are given in L<perldsc> and L<perllol>. Examples of diff --git a/pod/perlfaq5.pod b/pod/perlfaq5.pod index 898864b51a..03d5e6a797 100644 --- a/pod/perlfaq5.pod +++ b/pod/perlfaq5.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq5 - Files and Formats ($Revision: 1.21 $, $Date: 1997/04/23 18:05:19 $) +perlfaq5 - Files and Formats ($Revision: 1.22 $, $Date: 1997/04/24 22:44:02 $) =head1 DESCRIPTION @@ -451,8 +451,7 @@ over NFS, so this won't work (at least, not every time) over the net. Various schemes involving involving link() have been suggested, but these tend to involve busy-wait, which is also subdesirable. -=head2 I still don't get locking. I just want to increment the number -in the file. How can I do this? +=head2 I still don't get locking. I just want to increment the number in the file. How can I do this? Didn't anyone ever tell you web-page hit counters were useless? diff --git a/pod/perlfaq6.pod b/pod/perlfaq6.pod index 1af7948339..d21a11157b 100644 --- a/pod/perlfaq6.pod +++ b/pod/perlfaq6.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq6 - Regexps ($Revision: 1.16 $, $Date: 1997/03/25 18:16:56 $) +perlfaq6 - Regexps ($Revision: 1.17 $, $Date: 1997/04/24 22:44:10 $) =head1 DESCRIPTION @@ -138,7 +138,8 @@ on matching balanced text. $/ must be a string, not a regular expression. Awk has to be better for something. :-) -Actually, you could do this if you don't mind reading the whole file into +Actually, you could do this if you don't mind reading the whole file +into memory: undef $/; @records = split /your_pattern/, <FH>; @@ -325,9 +326,9 @@ playing hot potato. Use the split function: while (<>) { - foreach $word ( split ) { + foreach $word ( split ) { # do something with $word here - } + } } Note that this isn't really a word in the English sense; it's just @@ -360,7 +361,7 @@ in the previous question: If you wanted to do the same thing for lines, you wouldn't need a regular expression: - while (<>) { + while (<>) { $seen{$_}++; } while ( ($line, $count) = each %seen ) { @@ -546,19 +547,20 @@ synonymous. The following set of approaches was offered by Jeffrey Friedl, whose article in issue #5 of The Perl Journal talks about this very matter. -Let's suppose you have some weird Martian encoding where pairs of ASCII -uppercase letters encode single Martian letters (i.e. the two bytes -"CV" make a single Martian letter, as do the two bytes "SG", "VS", -"XX", etc.). Other bytes represent single characters, just like ASCII. +Let's suppose you have some weird Martian encoding where pairs of +ASCII uppercase letters encode single Martian letters (i.e. the two +bytes "CV" make a single Martian letter, as do the two bytes "SG", +"VS", "XX", etc.). Other bytes represent single characters, just like +ASCII. -So, the string of Martian "I am CVSGXX!" uses 12 bytes to encode the nine -characters 'I', ' ', 'a', 'm', ' ', 'CV', 'SG', 'XX', '!'. +So, the string of Martian "I am CVSGXX!" uses 12 bytes to encode the +nine characters 'I', ' ', 'a', 'm', ' ', 'CV', 'SG', 'XX', '!'. Now, say you want to search for the single character C</GX/>. Perl -doesn't know about Martian, so it'll find the two bytes "GX" in the -"I am CVSGXX!" string, even though that character isn't there: it just -looks like it is because "SG" is next to "XX", but there's no real "GX". -This is a big problem. +doesn't know about Martian, so it'll find the two bytes "GX" in the "I +am CVSGXX!" string, even though that character isn't there: it just +looks like it is because "SG" is next to "XX", but there's no real +"GX". This is a big problem. Here are a few ways, all painful, to deal with it: diff --git a/pod/perlfaq7.pod b/pod/perlfaq7.pod index 908fc14e7c..283aa2bb34 100644 --- a/pod/perlfaq7.pod +++ b/pod/perlfaq7.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq7 - Perl Language Issues ($Revision: 1.16 $, $Date: 1997/03/19 17:25:23 $) +perlfaq7 - Perl Language Issues ($Revision: 1.18 $, $Date: 1997/04/24 22:44:14 $) =head1 DESCRIPTION @@ -169,7 +169,7 @@ own module. Make sure to change the names appropriately. # if using RCS/CVS, this next line may be preferred, # but beware two-digit versions. - $VERSION = do{my@r=q$Revision: 1.16 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r}; + $VERSION = do{my@r=q$Revision: 1.18 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r}; @ISA = qw(Exporter); @EXPORT = qw(&func1 &func2 &func3); @@ -709,6 +709,8 @@ Use embedded POD to discard it: =end comment text + =cut + =head1 AUTHOR AND COPYRIGHT Copyright (c) 1997 Tom Christiansen and Nathan Torkington. diff --git a/pod/perlfaq8.pod b/pod/perlfaq8.pod index f559d6a2f2..0c91f1e8de 100644 --- a/pod/perlfaq8.pod +++ b/pod/perlfaq8.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq8 - System Interaction ($Revision: 1.20 $, $Date: 1997/04/23 18:11:50 $) +perlfaq8 - System Interaction ($Revision: 1.21 $, $Date: 1997/04/24 22:44:19 $) =head1 DESCRIPTION @@ -795,7 +795,394 @@ The latter is particularly useful because it knows about machine dependent architectures. The lib.pm pragmatic module was first included with the 5.002 release of Perl. +=head1 How do I get one key from the terminal at a time, under POSIX? + + #!/usr/bin/perl -w + use strict; + $| = 1; + for (1..4) { + my $got; + print "gimme: "; + $got = getone(); + print "--> $got\n"; + } + exit; + + BEGIN { + use POSIX qw(:termios_h); + + my ($term, $oterm, $echo, $noecho, $fd_stdin); + + $fd_stdin = fileno(STDIN); + + $term = POSIX::Termios->new(); + $term->getattr($fd_stdin); + $oterm = $term->getlflag(); + + $echo = ECHO | ECHOK | ICANON; + $noecho = $oterm & ~$echo; + + sub cbreak { + $term->setlflag($noecho); + $term->setcc(VTIME, 1); + $term->setattr($fd_stdin, TCSANOW); + } + + sub cooked { + $term->setlflag($oterm); + $term->setcc(VTIME, 0); + $term->setattr($fd_stdin, TCSANOW); + } + + sub getone { + my $key = ''; + cbreak(); + sysread(STDIN, $key, 1); + cooked(); + return $key; + } + + } + END { cooked() } + +=head1 AUTHOR AND COPYRIGHT + +Copyright (c) 1997 Tom Christiansen and Nathan Torkington. +All rights reserved. See L<perlfaq> for distribution information. + END-of-perlfaq8.pod +echo x - perlfaq9.pod +sed 's/^X//' >perlfaq9.pod << 'END-of-perlfaq9.pod' +=head1 NAME + +perlfaq9 - Networking ($Revision: 1.17 $, $Date: 1997/04/24 22:44:29 $) + +=head1 DESCRIPTION + +This section deals with questions related to networking, the internet, +and a few on the web. + +=head2 My CGI script runs from the command line but not the browser. Can you help me fix it? + +Sure, but you probably can't afford our contracting rates :-) + +Seriously, if you can demonstrate that you've read the following FAQs +and that your problem isn't something simple that can be easily +answered, you'll probably receive a courteous and useful reply to your +question if you post it on comp.infosystems.www.authoring.cgi (if it's +something to do with HTTP, HTML, or the CGI protocols). Questions that +appear to be Perl questions but are really CGI ones that are posted to +comp.lang.perl.misc may not be so well received. + +The useful FAQs are: + + http://www.perl.com/perl/faq/idiots-guide.html + http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml + http://www.perl.com/perl/faq/perl-cgi-faq.html + http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html + http://www.boutell.com/faq/ + +=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 libwww-perl distribution, which is a must-have +module for all web hackers). + +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 +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<<> for example. + +Here's one "simple-minded" approach, that works for most files: + + #!/usr/bin/perl -p0777 + s/<(?:[^>'"]*|(['"]).*?\1)*>//gs + +If you want a more complete solution, see the 3-stage striphtml +program in +http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz +. + +=head2 How do I extract URLs? + +A quick but imperfect approach is + + #!/usr/bin/perl -n00 + # qxurl - tchrist@perl.com + print "$2\n" while m{ + < \s* + A \s+ HREF \s* = \s* (["']) (.*?) \1 + \s* > + }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. + +=head2 How do I download a file from the user's machine? How do I open a file on another machine? + +In the context of an HTML form, you can use what's known as +B<multipart/form-data> encoding. The CGI.pm module (available from +CPAN) supports this in the start_multipart_form() method, which isn't +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 +module (available from CPAN) supports this widget, as well as many +others, including some that it cleverly synthesizes on its own. + +=head2 How do I fetch an HTML file? + +One approach, if you have the lynx text-based HTML browser installed +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: + + # print HTML from a URL + use LWP::Simple; + getprint "http://www.sn.no/libwww-perl/"; + + # print ASCII from HTML from a URL + use LWP::Simple; + use HTML::Parse; + use HTML::FormatText; + my ($html, $ascii); + $html = get("http://www.perl.com/"); + defined $html + or die "Can't fetch HTML from http://www.perl.com/"; + $ascii = HTML::FormatText->new->format(parse_html($html)); + print $ascii; + +=head2 how do I decode or create those %-encodings on the web? + +Here's an example of decoding: + + $string = "http://altavista.digital.com/cgi-bin/query?pg=q&what=news&fmt=.&q=%2Bcgi-bin+%2Bperl.exe"; + $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-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. + +=head2 How do I redirect to another page? + +Instead of sending back a C<Content-Type> as the headers of your +reply, send back a C<Location:> header. Officially this should be a +C<URI:> header, so the CGI.pm module (available from CPAN) sends back +both: + + Location: http://www.domain.com/newpage + URI: http://www.domain.com/newpage + +Note that relative URLs in these headers can cause strange effects +because of "optimizations" that servers do. + +=head2 How do I put a password on my web pages? + +That depends. You'll need to read the documentation for your web +server, or perhaps check some of the other FAQs referenced above. + +=head2 How do I edit my .htpasswd and .htgroup files with Perl? + +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, Berkley 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: + + 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? + +Read the CGI security FAQ, at +http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html, and the +Perl/CGI FAQ at +http://www.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html. + +In brief: use tainting (see L<perlsec>), which makes sure that data +from outside your script (eg, CGI parameters) are never used in +C<eval> or C<system> calls. In addition to tainting, never use the +single-argument form of system() or exec(). Instead, supply the +command and arguments as a list, which prevents shell globbing. + +=head2 How do I parse an email header? + +For a quick-and-dirty solution, try this solution derived +from page 222 of the 2nd edition of "Programming Perl": + + $/ = ''; + $header = <MSG>; + $header =~ s/\n\s+/ /g; # merge continuation lines + %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header ); + +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 Mail::Header module from CPAN (part of the MailTools package). + +=head2 How do I decode a CGI form? + +A lot of people are tempted to code this up themselves, so you've +probably all seen a lot of code involving C<$ENV{CONTENT_LENGTH}> and +C<$ENV{QUERY_STRING}>. It's true that this can work, but there are +also a lot of versions of this floating around that are quite simply +broken! + +Please do not be tempted to reinvent the wheel. Instead, use the +CGI.pm or CGI_Lite.pm (available from CPAN), or if you're trapped in +the module-free land of perl1 .. perl4, you might look into cgi-lib.pl +(available from http://www.bio.cam.ac.uk/web/form.html). + +=head2 How do I check a valid email address? + +You can't. + +Without sending mail to the address and seeing whether it bounces (and +even then you face the halting problem), you cannot determine whether +an email address is valid. Even if you apply the email header +standard, you can have problems, because there are deliverable +addresses that aren't 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 email +addresses with a simple regexp, such as +C</^[\w.-]+\@([\w.-]\.)+\w+$/>. However, this also throws out many +valid ones, and says nothing about potential deliverability, so is not +suggested. Instead, see +http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz , +which actually checks against the full RFC spec (except for nested +comments), looks for addresses you may not wish to accept email to +(say, Bill Clinton or your postmaster), and then makes sure that the +hostname given can be looked up in DNS. It's not fast, but it works. + +Here's an alternative strategy used by many CGI script authors: Check +the email address with a simple regexp (such as the one above). If +the regexp matched the address, accept the address. If the regexp +didn't match the address, request confirmation from the user that the +email address they entered was correct. + +=head2 How do I decode a MIME/BASE64 string? + +The MIME-tools package (available from CPAN) handles this and a lot +more. Decoding BASE64 becomes as simple as: + + use MIME::base64; + $decoded = decode_base64($encoded); + +A more direct approach is to use the unpack() function's "u" +format after minor transliterations: + + 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 email address? + +On systems that support getpwuid, the $E<lt> 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); + +Company policies on email address can mean that this generates addresses +that the company's email system will not accept, so you should ask for +users' email addresses when this matters. Furthermore, not all systems +on which Perl runs are so forthcoming with this information as is Unix. + +The Mail::Util module from CPAN (part of the MailTools package) provides a +mailaddress() 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. + +=head2 How do I send/read mail? + +Sending mail: the Mail::Mailer module from CPAN (part of the MailTools +package) is UNIX-centric, while Mail::Internet uses Net::SMTP which is +not UNIX-centric. Reading 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; + +=head2 How do I find out my hostname/domainname/IP address? + +A lot of code has historically cavalierly called the C<`hostname`> +program. While sometimes expedient, this isn't very portable. It's +one of those tradeoffs of convenience versus portability. + +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. + + use Socket; + use Sys::Hostname; + my $host = hostname(); + my $addr = inet_ntoa(scalar(gethostbyname($name)) || 'localhost'); + +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. + +(We still need a good DNS domain name-learning method for non-Unix +systems.) + +=head2 How do I fetch a news article or the active newsgroups? + +Use the Net::NNTP or News::NNTPClient modules, both available from CPAN. +This can make tasks like fetching the newsgroup list as simple as: + + perl -MNews::NNTPClient + -e 'print News::NNTPClient->new->list("newsgroups")' + +=head2 How do I fetch/put an FTP file? + +LWP::Simple (available from CPAN) can fetch but not put. Net::FTP (also +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). No ONC::RPC module is known. + =head1 AUTHOR AND COPYRIGHT Copyright (c) 1997 Tom Christiansen and Nathan Torkington. All rights reserved. See L<perlfaq> for distribution information. + +END-of-perlfaq9.pod +exit + diff --git a/pod/perltoc.pod b/pod/perltoc.pod index a70ed6e74e..b699e7fd30 100644 --- a/pod/perltoc.pod +++ b/pod/perltoc.pod @@ -38,8 +38,8 @@ expression enhancements, Innumerable Unbundled Modules, Compilability =item NOTES -=head2 perlfaq - frequently asked questions about Perl ($Date: 1997/04/23 -18:11:06 $) +=head2 perlfaq - frequently asked questions about Perl ($Date: 1997/04/24 +22:46:06 $) =item DESCRIPTION @@ -76,11 +76,11 @@ authors =item Changes -23/April/97, 25/March/97, 18/March/97, 17/March/97 Version, Initial -Release: 11/March/97 +24/April/97, 23/April/97, 25/March/97, 18/March/97, 17/March/97 Version, +Initial Release: 11/March/97 -=head2 perlfaq1 - General Questions About Perl ($Revision: 1.11 $, $Date: -1997/03/19 17:23:09 $) +=head2 perlfaq1 - General Questions About Perl ($Revision: 1.12 $, $Date: +1997/04/24 22:43:34 $) =item DESCRIPTION @@ -176,8 +176,8 @@ MacPerl, Perl5-Porters, NTPerl, Perl-Packrats =item AUTHOR AND COPYRIGHT -=head2 perlfaq3 - Programming Tools ($Revision: 1.21 $, $Date: 1997/04/23 -18:04:23 $) +=head2 perlfaq3 - Programming Tools ($Revision: 1.22 $, $Date: 1997/04/24 +22:43:42 $) =item DESCRIPTION @@ -251,8 +251,8 @@ mean? =item AUTHOR AND COPYRIGHT -=head2 perlfaq4 - Data Manipulation ($Revision: 1.18 $, $Date: 1997/04/23 -18:04:37 $) +=head2 perlfaq4 - Data Manipulation ($Revision: 1.19 $, $Date: 1997/04/24 +22:43:57 $) =item DESCRIPTION @@ -418,8 +418,8 @@ it? =item Why does passing a subroutine an undefined element in a hash create it? -=item How can I make the Perl equivalent of a C structure/C++ class/hash -or array of hashes or arrays? +=item How can I make the Perl equivalent of a C structure/C++ class/hash or +array of hashes or arrays? =item How can I use a reference as a hash key? @@ -445,8 +445,8 @@ or array of hashes or arrays? =item AUTHOR AND COPYRIGHT -=head2 perlfaq5 - Files and Formats ($Revision: 1.21 $, $Date: 1997/04/23 -18:05:19 $) +=head2 perlfaq5 - Files and Formats ($Revision: 1.22 $, $Date: 1997/04/24 +22:44:02 $) =item DESCRIPTION @@ -488,8 +488,8 @@ filehandles between subroutines? How do I make an array of filehandles? =item What can't I just open(FH, ">file.lock")? -=item I still don't get locking. I just want to increment the number -in the file. How can I do this? +=item I still don't get locking. I just want to increment the number in +the file. How can I do this? =item How do I randomly update a binary file? @@ -529,7 +529,7 @@ protected files? Isn't this a bug in Perl? =item AUTHOR AND COPYRIGHT -=head2 perlfaq6 - Regexps ($Revision: 1.16 $, $Date: 1997/03/25 18:16:56 $) +=head2 perlfaq6 - Regexps ($Revision: 1.17 $, $Date: 1997/04/24 22:44:10 $) =item DESCRIPTION @@ -590,8 +590,8 @@ file? =item AUTHOR AND COPYRIGHT -=head2 perlfaq7 - Perl Language Issues ($Revision: 1.16 $, $Date: -1997/03/19 17:25:23 $) +=head2 perlfaq7 - Perl Language Issues ($Revision: 1.18 $, $Date: +1997/04/24 22:44:14 $) =item DESCRIPTION @@ -661,8 +661,8 @@ is in scope? =item AUTHOR AND COPYRIGHT -=head2 perlfaq8 - System Interaction ($Revision: 1.20 $, $Date: 1997/04/23 -18:11:50 $) +=head2 perlfaq8 - System Interaction ($Revision: 1.21 $, $Date: 1997/04/24 +22:44:19 $) =item DESCRIPTION @@ -771,6 +771,61 @@ search path? =back +=item How do I get one key from the terminal at a time, under POSIX? + +=item AUTHOR AND COPYRIGHT + +=item DESCRIPTION + +=over + +=item My CGI script runs from the command line but not the browser. Can +you help me fix it? + +=item How do I remove HTML from a string? + +=item How do I extract URLs? + +=item How do I download a file from the user's machine? How do I open a +file on another machine? + +=item How do I make a pop-up menu in HTML? + +=item How do I fetch an HTML file? + +=item how do I decode or create those %-encodings on the web? + +=item How do I redirect to another page? + +=item How do I put a password on my web pages? + +=item How do I edit my .htpasswd and .htgroup files with Perl? + +=item How do I make sure users can't enter values into a form that cause my +CGI script to do bad things? + +=item How do I parse an email header? + +=item How do I decode a CGI form? + +=item How do I check a valid email address? + +=item How do I decode a MIME/BASE64 string? + +=item How do I return the user's email address? + +=item How do I send/read mail? + +=item How do I find out my hostname/domainname/IP address? + +=item How do I fetch a news article or the active newsgroups? + +=item How do I fetch/put an FTP file? + +=item How can I do RPC in Perl? + +=back + =item AUTHOR AND COPYRIGHT =head2 perlfaq9 - Networking ($Revision: 1.16 $, $Date: 1997/04/23 18:12:06 |