(No appreciable diffs this time. --tchrist)
[Last changed: $Date: 91/09/13 15:51:30 $ by $Author: tchrist $]
This article contains answers to some of the most frequently asked questions
in comp.lang.perl. They're all good questions, but they come up often enough
that substantial net bandwidth can be saved by looking here first before
asking. Before posting a question, you really should consult the Perl man
page; there's a lot of information packed in there.
Some questions in this group aren't really about Perl, but rather about
system-specific issues. You might also consult the Most Frequently Asked
Questions list in comp.unix.questions for answers to this type of question.
This list is maintained by Tom Christiansen. If you have any suggested
additions or corrections to this article, please send them to him at either
initially reviewing this list for accuracy and especially for writing and
releasing Perl in the first place.
List of Questions:
1) What is Perl?
2) Where can I get Perl?
3) How can I get Perl via UUCP?
4) Where can I get more documentation and examples for Perl?
5) Are archives of comp.lang.perl available?
6) How do I get Perl to run on machine FOO?
8) Why don't backticks work as they do in shells?
9) How come Perl operators have different precedence than C operators?
10) How come my converted awk/sed/sh script runs more slowly in Perl?
11) There's an a2p and an s2p; why isn't there a p2c?
12) Where can I get undump for my machine?
13) How can I call my system's unique C functions from Perl?
14) Where do I get the include files to do ioctl() or syscall()?
15) Why doesn't "local($foo) = <FILE>;" work right?
16) How can I detect keyboard input without reading it?
17) How can I make an array of arrays or other recursive data types?
18) How can I quote a variable to use in a regexp?
19) Why do setuid Perl scripts complain about kernel problems?
20) How do I open a pipe both to and from a command?
21) How can I change the first N letters of a string?
22) How can I manipulate fixed-record-length files?
23) How can I make a file handle local to a subroutine?
24) How can I extract just the unique elements of an array?
25) How can I call alarm() from Perl?
26) How can I test whether an array contains a certain element?
27) How can I do an atexit() or setjmp()/longjmp() in Perl?
28) Why doesn't Perl interpret my octal data octally?
29) Where can I get a perl-mode for emacs?
30) How can I use Perl interactively?
31) How do a sort an associative array by value instead of by key?
32) How can I capture STDERR from an external command?
33) Why doesn't open return an error when a pipe open fails?
To skip ahead to a particular question, such as question 17, you can
search for the regular expression "^17)". Most pagers (more or less)
do this with the command /^17) followed by a carriage return.
1) What is Perl?
Here's the beginning of the description from the man page:
Perl is an interpreted language optimized for scanning arbitrary text
files, extracting information from those text files, and printing reports
based on that information. It's also a good language for many system
management tasks. The language is intended to be practical (easy to use,
efficient, complete) rather than beautiful (tiny, elegant, minimal). It
combines (in the author's opinion, anyway) some of the best features of C,
sed, awk, and sh, so people familiar with those languages should have
little difficulty with it. (Language historians will also note some
vestiges of csh, Pascal, and even BASIC-PLUS.) Expression syntax
corresponds quite closely to C expression syntax. Unlike most Unix
utilities, Perl does not arbitrarily limit the size of your data--if
you've got the memory, Perl can slurp in your whole file as a single
string. Recursion is of unlimited depth. And the hash tables used by
associative arrays grow as necessary to prevent degraded performance.
Perl uses sophisticated pattern matching techniques to scan large amounts
of data very quickly. Although optimized for scanning text, Perl can also
deal with binary data, and can make dbm files look like associative arrays
(where dbm is available). Setuid Perl scripts are safer than C programs
through a dataflow tracing mechanism which prevents many stupid security
holes. If you have a problem that would ordinarily use sed or awk or sh,
but it exceeds their capabilities or must run a little faster, and you
don't want to write the silly thing in C, then Perl may be for you. There
are also translators to turn your sed and awk scripts into Perl scripts.
2) Where can I get Perl?
From any comp.sources.unix archive. These machines, at the very least,
definitely have it available for anonymous FTP:
ftp.uu.net 137.39.1.2
archive.cis.ohio-state.edu 128.146.8.52
jpl-devvax.jpl.nasa.gov 128.149.1.143
If you are in Europe, you might using the following site. This
FTP: Perl stuff is in the UNIX directory on archive.cs.ruu.nl (131.211.80.5)
begin
path your_email_address
send help
send UNIX/INDEX
end
The path-line may be omitted if your message contains a normal From:-line.
You will receive a help-file and an index of the directory that contains
the Perl stuff.
3) How can I get Perl via UUCP?
You can get it from the site osu-cis; here is the appropriate info,
E-mail contact:
osu-cis!uucp
Get these two files first:
osu-cis!~/GNU.how-to-get.
osu-cis!~/ls-lR.Z
Current Perl distribution:
How to reach osu-cis via uucp(L.sys/Systems file lines):
#
# Direct Trailblazer
#
osu-cis Any ACU 19200 1-614-292-5112 in:--in:--in: Uanon
#
# Direct V.32 (MNP 4)
# dead, dead, dead...sigh.
#
#osu-cis Any ACU 9600 1-614-292-1153 in:--in:--in: Uanon
#
# Micom port selector, at 1200, 2400, or 9600 bps.
# Replace ##'s below with 12, 24, or 96 (both speed and phone number).
#
osu-cis Any ACU ##00 1-614-292-31## "" \r\c Name? osu-cis nected \c GO \d\r\d\r\d\r in:--in:--in:
Uanon
Modify as appropriate for your site, of course, to deal with your
local telephone system. There are no limitations concerning the hours
of the day you may call.
Another possiblity is to use UUNET, although they charge you
for it. You have been duly warned. Here's the advert:
Anonymous Access to UUNET's Source Archives
1-900-GOT-SRCS
UUNET now provides access to its extensive collection of UNIX
related sources to non- subscribers. By calling 1-900-468-7727
and using the login "uucp" with no password, anyone may uucp any
of UUNET's on line source collection. Callers will be charged 40
cents per minute. The charges will appear on their next tele-
phone bill.
The file uunet!~/help contains instructions. The file
uunet!~/ls-lR.Z contains a complete list of the files available
and is updated daily. Files ending in Z need to be uncompressed
before being used. The file uunet!~/compress.tar is a tar
archive containing the C sources for the uncompress program.
This service provides a cost effective way of obtaining
current releases of sources without having to maintain accounts
with UUNET or some other service. All modems connected to the
900 number are Telebit T2500 modems. These modems support all
standard modem speeds including PEP, V.32 (9600), V.22bis (2400),
Bell 212a (1200), and Bell 103 (300). Using PEP or V.32, a 1.5
megabyte file such as the GNU C compiler would cost $10 in con-
nect charges. The entire 55 megabyte X Window system V11 R4
would cost only $370 in connect time. These costs are less than
the official tape distribution fees and they are available now
via modem.
UUNET Communications Services
3110 Fairview Park Drive, Suite 570
Falls Church, VA 22042
+1 703 876 5050 (voice)
+1 703 876 5059 (fax)
4) Where can I get more documentation and examples for Perl?
If you've been dismayed by the ~75-page Perl man page (or is that man
treatise?) you should look to ``the Camel Book'', written by Larry and
Handbook by O'Reilly & Associates and entitled _Programming Perl_.
Besides serving as a reference guide for Perl, it also contains
tutorial material, is a great source of examples and cookbook
procedures, as well as wit and wisdom, tricks and traps, pranks and
pitfalls. The code examples contained therein are available via
anonymous FTP from ftp.uu.net in nutshell/perl/perl.tar.Z for your
retrieval.
If you can't find the book in your local technical bookstore, the book
may be ordered directly from O'Reilly by calling 1-800-dev-nuts if in
North America (that's 1-800-338-6887 for those poor folks without
handy mnemonic numbers on their phones) and 1-707-829-0515.
Autographed copies are available from TECHbooks by calling
regular version, 40$US for the special autographed one.
The book's ISBN is
...
read more »