This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bad \[...] prototype checking
[perl5.git] / pod / perlfaq9.pod
CommitLineData
68dc0745 1=head1 NAME
2
213329dd 3perlfaq9 - Networking ($Revision: 1.5 $, $Date: 2001/11/09 08:06:04 $)
68dc0745 4
5=head1 DESCRIPTION
6
7This section deals with questions related to networking, the internet,
8and a few on the web.
9
24f1ba9b 10=head2 What is the correct form of response from a CGI script?
68dc0745 11
24f1ba9b
JH
12(Alan Flavell <flavell+www@a5.ph.gla.ac.uk> answers...)
13
14The Common Gateway Interface (CGI) specifies a software interface between
15a program ("CGI script") and a web server (HTTPD). It is not specific
16to Perl, and has its own FAQs and tutorials, and usenet group,
17comp.infosystems.www.authoring.cgi
18
19The original CGI specification is at: http://hoohoo.ncsa.uiuc.edu/cgi/
20
21Current best-practice RFC draft at: http://CGI-Spec.Golux.Com/
22
23Other relevant documentation listed in: http://www.perl.org/CGI_MetaFAQ.html
68dc0745 24
24f1ba9b
JH
25These Perl FAQs very selectively cover some CGI issues. However, Perl
26programmers are strongly advised to use the CGI.pm module, to take care
27of the details for them.
68dc0745 28
24f1ba9b
JH
29The similarity between CGI response headers (defined in the CGI
30specification) and HTTP response headers (defined in the HTTP
31specification, RFC2616) is intentional, but can sometimes be confusing.
68dc0745 32
24f1ba9b
JH
33The CGI specification defines two kinds of script: the "Parsed Header"
34script, and the "Non Parsed Header" (NPH) script. Check your server
35documentation to see what it supports. "Parsed Header" scripts are
36simpler in various respects. The CGI specification allows any of the
37usual newline representations in the CGI response (it's the server's
38job to create an accurate HTTP response based on it). So "\n" written in
39text mode is technically correct, and recommended. NPH scripts are more
40tricky: they must put out a complete and accurate set of HTTP
41transaction response headers; the HTTP specification calls for records
42to be terminated with carriage-return and line-feed, i.e ASCII \015\012
43written in binary mode.
68dc0745 44
24f1ba9b
JH
45Using CGI.pm gives excellent platform independence, including EBCDIC
46systems. CGI.pm selects an appropriate newline representation
47($CGI::CRLF) and sets binmode as appropriate.
c8db1d39 48
24f1ba9b 49=head2 My CGI script runs from the command line but not the browser. (500 Server Error)
c8db1d39 50
24f1ba9b
JH
51If you can demonstrate that you've read the FAQs and that
52your problem isn't something simple that can be easily answered, you'll
53probably receive a courteous and useful reply to your question if you
54post it on comp.infosystems.www.authoring.cgi (if it's something to do
55with HTTP or the CGI protocols). Questions that appear to be Perl
56questions but are really CGI ones that are posted to comp.lang.perl.misc
57are not so well received.
c8db1d39 58
24f1ba9b
JH
59The useful FAQs, related documents, and troubleshooting guides are
60listed in the CGI Meta FAQ:
61
62 http://www.perl.org/CGI_MetaFAQ.html
c8db1d39 63
c8db1d39
TC
64
65=head2 How can I get better error messages from a CGI program?
66
67Use the CGI::Carp module. It replaces C<warn> and C<die>, plus the
68normal Carp modules C<carp>, C<croak>, and C<confess> functions with
69more verbose and safer versions. It still sends them to the normal
70server error log.
71
72 use CGI::Carp;
73 warn "This is a complaint";
74 die "But this one is serious";
75
76The following use of CGI::Carp also redirects errors to a file of your choice,
77placed in a BEGIN block to catch compile-time warnings as well:
78
79 BEGIN {
80 use CGI::Carp qw(carpout);
81 open(LOG, ">>/var/local/cgi-logs/mycgi-log")
82 or die "Unable to append to mycgi-log: $!\n";
83 carpout(*LOG);
84 }
85
86You can even arrange for fatal errors to go back to the client browser,
87which is nice for your own debugging, but might confuse the end user.
88
89 use CGI::Carp qw(fatalsToBrowser);
90 die "Bad error here";
91
92Even if the error happens before you get the HTTP header out, the module
93will try to take care of this to avoid the dreaded server 500 errors.
94Normal warnings still go out to the server error log (or wherever
95you've sent them with C<carpout>) with the application name and date
96stamp prepended.
97
68dc0745 98=head2 How do I remove HTML from a string?
99
f29c64d6 100The most correct way (albeit not the fastest) is to use HTML::Parser
bed171df 101from CPAN. Another mostly correct
7d7e76cf
MS
102way is to use HTML::FormatText which not only removes HTML but also
103attempts to do a little simple formatting of the resulting plain text.
68dc0745 104
105Many folks attempt a simple-minded regular expression approach, like
c47ff5f1 106C<< s/<.*?>//g >>, but that fails in many cases because the tags
68dc0745 107may continue over line breaks, they may contain quoted angle-brackets,
a6dd486b
JB
108or HTML comment may be present. Plus, folks forget to convert
109entities--like C<&lt;> for example.
68dc0745 110
111Here's one "simple-minded" approach, that works for most files:
112
113 #!/usr/bin/perl -p0777
114 s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
115
116If you want a more complete solution, see the 3-stage striphtml
117program in
a93751fa 118http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz
68dc0745 119.
120
c8db1d39
TC
121Here are some tricky cases that you should think about when picking
122a solution:
123
124 <IMG SRC = "foo.gif" ALT = "A > B">
125
d92eb7b0 126 <IMG SRC = "foo.gif"
c8db1d39
TC
127 ALT = "A > B">
128
129 <!-- <A comment> -->
130
131 <script>if (a<b && a>c)</script>
132
133 <# Just data #>
134
135 <![INCLUDE CDATA [ >>>>>>>>>>>> ]]>
136
137If HTML comments include other tags, those solutions would also break
138on text like this:
139
140 <!-- This section commented out.
141 <B>You can't see me!</B>
142 -->
143
68dc0745 144=head2 How do I extract URLs?
145
e67d034e
JH
146You can easily extract all sorts of URLs from HTML with
147C<HTML::SimpleLinkExtor> which handles anchors, images, objects,
148frames, and many other tags that can contain a URL. If you need
149anything more complex, you can create your own subclass of
150C<HTML::LinkExtor> or C<HTML::Parser>. You might even use
151C<HTML::SimpleLinkExtor> as an example for something specifically
152suited to your needs.
153
154Less complete solutions involving regular expressions can save
155you a lot of processing time if you know that the input is simple. One
156solution from Tom Christiansen runs 100 times faster than most
157module based approaches but only extracts URLs from anchors where the first
158attribute is HREF and there are no other attributes.
159
160 #!/usr/bin/perl -n00
161 # qxurl - tchrist@perl.com
162 print "$2\n" while m{
163 < \s*
164 A \s+ HREF \s* = \s* (["']) (.*?) \1
165 \s* >
166 }gsix;
167
68dc0745 168
169=head2 How do I download a file from the user's machine? How do I open a file on another machine?
170
171In the context of an HTML form, you can use what's known as
172B<multipart/form-data> encoding. The CGI.pm module (available from
173CPAN) supports this in the start_multipart_form() method, which isn't
174the same as the startform() method.
175
176=head2 How do I make a pop-up menu in HTML?
177
c47ff5f1 178Use the B<< <SELECT> >> and B<< <OPTION> >> tags. The CGI.pm
68dc0745 179module (available from CPAN) supports this widget, as well as many
180others, including some that it cleverly synthesizes on its own.
181
182=head2 How do I fetch an HTML file?
183
46fc3d4c 184One approach, if you have the lynx text-based HTML browser installed
185on your system, is this:
68dc0745 186
187 $html_code = `lynx -source $url`;
188 $text_data = `lynx -dump $url`;
189
d92eb7b0
GS
190The libwww-perl (LWP) modules from CPAN provide a more powerful way
191to do this. They don't require lynx, but like lynx, can still work
192through proxies:
46fc3d4c 193
c8db1d39
TC
194 # simplest version
195 use LWP::Simple;
196 $content = get($URL);
197
198 # or print HTML from a URL
46fc3d4c 199 use LWP::Simple;
6cecdcac 200 getprint "http://www.linpro.no/lwp/";
46fc3d4c 201
c8db1d39 202 # or print ASCII from HTML from a URL
65acb1b1 203 # also need HTML-Tree package from CPAN
46fc3d4c 204 use LWP::Simple;
f29c64d6 205 use HTML::Parser;
46fc3d4c 206 use HTML::FormatText;
207 my ($html, $ascii);
208 $html = get("http://www.perl.com/");
209 defined $html
210 or die "Can't fetch HTML from http://www.perl.com/";
211 $ascii = HTML::FormatText->new->format(parse_html($html));
212 print $ascii;
213
c8db1d39
TC
214=head2 How do I automate an HTML form submission?
215
216If you're submitting values using the GET method, create a URL and encode
217the form using the C<query_form> method:
218
219 use LWP::Simple;
220 use URI::URL;
221
222 my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
223 $url->query_form(module => 'DB_File', readme => 1);
224 $content = get($url);
225
226If you're using the POST method, create your own user agent and encode
227the content appropriately.
228
229 use HTTP::Request::Common qw(POST);
230 use LWP::UserAgent;
231
232 $ua = LWP::UserAgent->new();
233 my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
234 [ module => 'DB_File', readme => 1 ];
235 $content = $ua->request($req)->as_string;
236
237=head2 How do I decode or create those %-encodings on the web?
68dc0745 238
68dc0745 239
575cc754
JH
240If you are writing a CGI script, you should be using the CGI.pm module
241that comes with perl, or some other equivalent module. The CGI module
242automatically decodes queries for you, and provides an escape()
243function to handle encoding.
68dc0745 244
575cc754
JH
245
246The best source of detailed information on URI encoding is RFC 2396.
247Basically, the following substitutions do it:
248
249 s/([^\w()'*~!.-])/sprintf '%%%02x', $1/eg; # encode
250
251 s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode
252
253However, you should only apply them to individual URI components, not
254the entire URI, otherwise you'll lose information and generally mess
255things up. If that didn't explain it, don't worry. Just go read
256section 2 of the RFC, it's probably the best explanation there is.
257
258RFC 2396 also contains a lot of other useful information, including a
259regexp for breaking any arbitrary URI into components (Appendix B).
68dc0745 260
261=head2 How do I redirect to another page?
262
24f1ba9b
JH
263Specify the complete URL of the destination (even if it is on the same
264server). This is one of the two different kinds of CGI "Location:"
265responses which are defined in the CGI specification for a Parsed Headers
266script. The other kind (an absolute URLpath) is resolved internally to
267the server without any HTTP redirection. The CGI specifications do not
268allow relative URLs in either case.
269
270Use of CGI.pm is strongly recommended. This example shows redirection
271with a complete URL. This redirection is handled by the web browser.
272
273 use CGI qw/:standard/;
274
a93751fa 275 my $url = 'http://www.cpan.org/';
24f1ba9b 276 print redirect($url);
68dc0745 277
68dc0745 278
24f1ba9b
JH
279This example shows a redirection with an absolute URLpath. This
280redirection is handled by the local web server.
68dc0745 281
24f1ba9b
JH
282 my $url = '/CPAN/index.html';
283 print redirect($url);
c8db1d39 284
d92eb7b0 285
24f1ba9b
JH
286But if coded directly, it could be as follows (the final "\n" is
287shown separately, for clarity), using either a complete URL or
288an absolute URLpath.
d92eb7b0 289
24f1ba9b
JH
290 print "Location: $url\n"; # CGI response header
291 print "\n"; # end of headers
d92eb7b0 292
c8db1d39 293
68dc0745 294=head2 How do I put a password on my web pages?
295
296That depends. You'll need to read the documentation for your web
297server, or perhaps check some of the other FAQs referenced above.
298
299=head2 How do I edit my .htpasswd and .htgroup files with Perl?
300
301The HTTPD::UserAdmin and HTTPD::GroupAdmin modules provide a
302consistent OO interface to these files, regardless of how they're
426affbf
LS
303stored. Databases may be text, dbm, Berkeley DB or any database with
304a DBI compatible driver. HTTPD::UserAdmin supports files used by the
68dc0745 305`Basic' and `Digest' authentication schemes. Here's an example:
306
307 use HTTPD::UserAdmin ();
308 HTTPD::UserAdmin
309 ->new(DB => "/foo/.htpasswd")
310 ->add($username => $password);
311
46fc3d4c 312=head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things?
313
24f1ba9b 314See the security references listed in the CGI Meta FAQ
46fc3d4c 315
24f1ba9b 316 http://www.perl.org/CGI_MetaFAQ.html
46fc3d4c 317
5a964f20 318=head2 How do I parse a mail header?
68dc0745 319
320For a quick-and-dirty solution, try this solution derived
b73a15ae 321from L<perlfunc/split>:
68dc0745 322
323 $/ = '';
324 $header = <MSG>;
325 $header =~ s/\n\s+/ /g; # merge continuation lines
326 %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );
327
328That solution doesn't do well if, for example, you're trying to
329maintain all the Received lines. A more complete approach is to use
330the Mail::Header module from CPAN (part of the MailTools package).
331
332=head2 How do I decode a CGI form?
333
c8db1d39
TC
334You use a standard module, probably CGI.pm. Under no circumstances
335should you attempt to do so by hand!
336
337You'll see a lot of CGI programs that blindly read from STDIN the number
338of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
339decoding GETs. These programs are very poorly written. They only work
340sometimes. They typically forget to check the return value of the read()
341system call, which is a cardinal sin. They don't handle HEAD requests.
342They don't handle multipart forms used for file uploads. They don't deal
343with GET/POST combinations where query fields are in more than one place.
344They don't deal with keywords in the query string.
345
346In short, they're bad hacks. Resist them at all costs. Please do not be
347tempted to reinvent the wheel. Instead, use the CGI.pm or CGI_Lite.pm
348(available from CPAN), or if you're trapped in the module-free land
349of perl1 .. perl4, you might look into cgi-lib.pl (available from
65acb1b1 350http://cgi-lib.stanford.edu/cgi-lib/ ).
c8db1d39
TC
351
352Make sure you know whether to use a GET or a POST in your form.
353GETs should only be used for something that doesn't update the server.
354Otherwise you can get mangled databases and repeated feedback mail
355messages. The fancy word for this is ``idempotency''. This simply
356means that there should be no difference between making a GET request
357for a particular URL once or multiple times. This is because the
358HTTP protocol definition says that a GET request may be cached by the
359browser, or server, or an intervening proxy. POST requests cannot be
360cached, because each request is independent and matters. Typically,
361POST requests change or depend on state on the server (query or update
362a database, send mail, or purchase a computer).
68dc0745 363
5a964f20 364=head2 How do I check a valid mail address?
68dc0745 365
c8db1d39 366You can't, at least, not in real time. Bummer, eh?
68dc0745 367
c8db1d39
TC
368Without sending mail to the address and seeing whether there's a human
369on the other hand to answer you, you cannot determine whether a mail
370address is valid. Even if you apply the mail header standard, you
371can have problems, because there are deliverable addresses that aren't
372RFC-822 (the mail header standard) compliant, and addresses that aren't
373deliverable which are compliant.
68dc0745 374
c8db1d39 375Many are tempted to try to eliminate many frequently-invalid
d92eb7b0 376mail addresses with a simple regex, such as
b8c8cfe2 377C</^[\w.-]+\@(?:[\w-]+\.)+\w+$/>. It's a very bad idea. However,
c8db1d39 378this also throws out many valid ones, and says nothing about
b8c8cfe2 379potential deliverability, so it is not suggested. Instead, see
a93751fa 380http://www.cpan.org/authors/Tom_Christiansen/scripts/ckaddr.gz,
68dc0745 381which actually checks against the full RFC spec (except for nested
5a964f20 382comments), looks for addresses you may not wish to accept mail to
68dc0745 383(say, Bill Clinton or your postmaster), and then makes sure that the
c8db1d39
TC
384hostname given can be looked up in the DNS MX records. It's not fast,
385but it works for what it tries to do.
386
387Our best advice for verifying a person's mail address is to have them
388enter their address twice, just as you normally do to change a password.
389This usually weeds out typos. If both versions match, send
390mail to that address with a personal message that looks somewhat like:
391
392 Dear someuser@host.com,
393
394 Please confirm the mail address you gave us Wed May 6 09:38:41
395 MDT 1998 by replying to this message. Include the string
396 "Rumpelstiltskin" in that reply, but spelled in reverse; that is,
397 start with "Nik...". Once this is done, your confirmed address will
398 be entered into our records.
399
400If you get the message back and they've followed your directions,
401you can be reasonably assured that it's real.
68dc0745 402
c8db1d39
TC
403A related strategy that's less open to forgery is to give them a PIN
404(personal ID number). Record the address and PIN (best that it be a
405random one) for later processing. In the mail you send, ask them to
406include the PIN in their reply. But if it bounces, or the message is
407included via a ``vacation'' script, it'll be there anyway. So it's
408best to ask them to mail back a slight alteration of the PIN, such as
409with the characters reversed, one added or subtracted to each digit, etc.
46fc3d4c 410
68dc0745 411=head2 How do I decode a MIME/BASE64 string?
412
6a0af2f1
GA
413The MIME-Base64 package (available from CPAN) handles this as well as
414the MIME/QP encoding. Decoding BASE64 becomes as simple as:
68dc0745 415
6a0af2f1 416 use MIME::Base64;
68dc0745 417 $decoded = decode_base64($encoded);
418
26d9b02f 419The MIME-Tools package (available from CPAN) supports extraction with
6a0af2f1
GA
420decoding of BASE64 encoded attachments and content directly from email
421messages.
422
423If the string to decode is short (less than 84 bytes long)
424a more direct approach is to use the unpack() function's "u"
68dc0745 425format after minor transliterations:
426
427 tr#A-Za-z0-9+/##cd; # remove non-base64 chars
428 tr#A-Za-z0-9+/# -_#; # convert to uuencoded format
429 $len = pack("c", 32 + 0.75*length); # compute length byte
430 print unpack("u", $len . $_); # uudecode and print
431
5a964f20 432=head2 How do I return the user's mail address?
68dc0745 433
a6dd486b 434On systems that support getpwuid, the $< variable, and the
68dc0745 435Sys::Hostname module (which is part of the standard perl distribution),
436you can probably try using something like this:
437
438 use Sys::Hostname;
231ab6d1 439 $address = sprintf('%s@%s', scalar getpwuid($<), hostname);
68dc0745 440
5a964f20
TC
441Company policies on mail address can mean that this generates addresses
442that the company's mail system will not accept, so you should ask for
443users' mail addresses when this matters. Furthermore, not all systems
68dc0745 444on which Perl runs are so forthcoming with this information as is Unix.
445
446The Mail::Util module from CPAN (part of the MailTools package) provides a
447mailaddress() function that tries to guess the mail address of the user.
448It makes a more intelligent guess than the code above, using information
449given when the module was installed, but it could still be incorrect.
450Again, the best way is often just to ask the user.
451
c8db1d39 452=head2 How do I send mail?
68dc0745 453
c8db1d39
TC
454Use the C<sendmail> program directly:
455
456 open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
457 or die "Can't fork for sendmail: $!\n";
458 print SENDMAIL <<"EOF";
459 From: User Originating Mail <me\@host>
460 To: Final Destination <you\@otherhost>
461 Subject: A relevant subject line
462
65acb1b1
TC
463 Body of the message goes here after the blank line
464 in as many lines as you like.
c8db1d39
TC
465 EOF
466 close(SENDMAIL) or warn "sendmail didn't close nicely";
467
468The B<-oi> option prevents sendmail from interpreting a line consisting
469of a single dot as "end of message". The B<-t> option says to use the
470headers to decide who to send the message to, and B<-odq> says to put
471the message into the queue. This last option means your message won't
472be immediately delivered, so leave it out if you want immediate
473delivery.
474
d92eb7b0
GS
475Alternate, less convenient approaches include calling mail (sometimes
476called mailx) directly or simply opening up port 25 have having an
477intimate conversation between just you and the remote SMTP daemon,
478probably sendmail.
479
480Or you might be able use the CPAN module Mail::Mailer:
c8db1d39
TC
481
482 use Mail::Mailer;
483
484 $mailer = Mail::Mailer->new();
485 $mailer->open({ From => $from_address,
486 To => $to_address,
487 Subject => $subject,
488 })
489 or die "Can't open: $!\n";
490 print $mailer $body;
491 $mailer->close();
492
493The Mail::Internet module uses Net::SMTP which is less Unix-centric than
494Mail::Mailer, but less reliable. Avoid raw SMTP commands. There
d92eb7b0 495are many reasons to use a mail transport agent like sendmail. These
8305e449 496include queuing, MX records, and security.
c8db1d39 497
575cc754
JH
498=head2 How do I use MIME to make an attachment to a mail message?
499
500This answer is extracted directly from the MIME::Lite documentation.
501Create a multipart message (i.e., one with attachments).
502
503 use MIME::Lite;
504
505 ### Create a new multipart message:
506 $msg = MIME::Lite->new(
507 From =>'me@myhost.com',
508 To =>'you@yourhost.com',
509 Cc =>'some@other.com, some@more.com',
510 Subject =>'A message with 2 parts...',
511 Type =>'multipart/mixed'
512 );
513
514 ### Add parts (each "attach" has same arguments as "new"):
515 $msg->attach(Type =>'TEXT',
516 Data =>"Here's the GIF file you wanted"
517 );
518 $msg->attach(Type =>'image/gif',
519 Path =>'aaa000123.gif',
520 Filename =>'logo.gif'
521 );
522
523 $text = $msg->as_string;
524
525MIME::Lite also includes a method for sending these things.
526
527 $msg->send;
528
529This defaults to using L<sendmail(1)> but can be customized to use
530SMTP via L<Net::SMTP>.
531
c8db1d39
TC
532=head2 How do I read mail?
533
d92eb7b0
GS
534While you could use the Mail::Folder module from CPAN (part of the
535MailFolder package) or the Mail::Internet module from CPAN (also part
a6dd486b 536of the MailTools package), often a module is overkill. Here's a
d92eb7b0
GS
537mail sorter.
538
539 #!/usr/bin/perl
c8db1d39
TC
540 # bysub1 - simple sort by subject
541 my(@msgs, @sub);
542 my $msgno = -1;
543 $/ = ''; # paragraph reads
544 while (<>) {
545 if (/^From/m) {
546 /^Subject:\s*(?:Re:\s*)*(.*)/mi;
547 $sub[++$msgno] = lc($1) || '';
548 }
549 $msgs[$msgno] .= $_;
d92eb7b0 550 }
c8db1d39
TC
551 for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) {
552 print $msgs[$i];
553 }
554
d92eb7b0 555Or more succinctly,
c8db1d39
TC
556
557 #!/usr/bin/perl -n00
558 # bysub2 - awkish sort-by-subject
559 BEGIN { $msgno = -1 }
560 $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m;
561 $msg[$msgno] .= $_;
562 END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] }
563
68dc0745 564=head2 How do I find out my hostname/domainname/IP address?
565
c8db1d39
TC
566The normal way to find your own hostname is to call the C<`hostname`>
567program. While sometimes expedient, this has some problems, such as
568not knowing whether you've got the canonical name or not. It's one of
569those tradeoffs of convenience versus portability.
68dc0745 570
571The Sys::Hostname module (part of the standard perl distribution) will
572give you the hostname after which you can find out the IP address
573(assuming you have working DNS) with a gethostbyname() call.
574
575 use Socket;
576 use Sys::Hostname;
577 my $host = hostname();
65acb1b1 578 my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
68dc0745 579
580Probably the simplest way to learn your DNS domain name is to grok
581it out of /etc/resolv.conf, at least under Unix. Of course, this
582assumes several things about your resolv.conf configuration, including
583that it exists.
584
585(We still need a good DNS domain name-learning method for non-Unix
586systems.)
587
588=head2 How do I fetch a news article or the active newsgroups?
589
590Use the Net::NNTP or News::NNTPClient modules, both available from CPAN.
a6dd486b 591This can make tasks like fetching the newsgroup list as simple as
68dc0745 592
593 perl -MNews::NNTPClient
594 -e 'print News::NNTPClient->new->list("newsgroups")'
595
596=head2 How do I fetch/put an FTP file?
597
598LWP::Simple (available from CPAN) can fetch but not put. Net::FTP (also
599available from CPAN) is more complex but can put as well as fetch.
600
601=head2 How can I do RPC in Perl?
602
a6dd486b 603A DCE::RPC module is being developed (but is not yet available) and
68dc0745 604will be released as part of the DCE-Perl package (available from
65acb1b1
TC
605CPAN). The rpcgen suite, available from CPAN/authors/id/JAKE/, is
606an RPC stub generator and includes an RPC::ONC module.
68dc0745 607
608=head1 AUTHOR AND COPYRIGHT
609
65acb1b1 610Copyright (c) 1997-1999 Tom Christiansen and Nathan Torkington.
5a964f20
TC
611All rights reserved.
612
5a7beb56
JH
613This documentation is free; you can redistribute it and/or modify it
614under the same terms as Perl itself.
5a964f20
TC
615
616Irrespective of its distribution, all code examples in this file
617are hereby placed into the public domain. You are permitted and
618encouraged to use this code in your own programs for fun
619or for profit as you see fit. A simple comment in the code giving
620credit would be courteous but is not required.