Perl Frequently Asked Questions List

August 16, 1995

This article details the contents of the most Frequently Asked Questions in comp.lang.perl.misc, a Usenet newsgroup devoted to the Perl programming language. There are five pieces following this, the general information questions in part1, part2 and part3 and the programming ones in part4 and part5.

If this is your first exposure to Perl, please read this document and the perl(1) man page before asking questions in comp.lang.perl.misc. If you're using v4 perl, that page contains all you need to know (or at least enough to get started). If you're using v5 perl, that page will show you where to look for specific information. When we refer to perlmod(1), it means the "perlmod" man page in section "1" of the manual, just as Foo(3pm), that means it's the "Foo" man page in section "3pm" (perl modules) of the library. The perl install does NOT automatically install the module man pages for you, however.

Hopefully the questions herein are asked enough that considerable net bandwidth can be saved by looking here before asking. Also, hopefully there is enough information contained here that someone who has never heard of Perl can read this and at least have some sort of idea as to what Perl is.

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.

The current version of perl is 5.001, perl 5.000 emerged into the world on 16 October, 1994. The previous non-beta version was 4.036 (version 4, patchlevel 36). Many of these questions were written for perl4, however a lot of perl5 information has also been added. Perl5 only features will be clearly marked as such, so as not to cause confusion for those still using perl4. You should upgrade to perl5 as soon as possible though (see below).

This list was initially written, and still hacked upon, by Tom Christiansen*. However, due to his erratic schedule, it is currently maintained by Stephen P Potter*. First person singular pronouns, when not in quoted postings, generally are Tom talking.

This document, and all its parts, are Copyright (c) 1994/1995, Stephen P Potter and Tom Christiansen, perlfaq@perl.com. All rights reserved. HTML by Tom Christiansen. Permisson to distribute this collection, in part or full, via electronic means (emailed, posted or archived) or printed copy are granted providing that no charges are involved, reasonable attempt is made to use the most current version, and all credits and copyright notices are retained. Requests for other distribution rights, including incorporation in commercial products, such as books, magazine articles, or CD-ROMs should be made to perlfaq@perl.com.

This FAQ is archived on ftp.cis.ufl.edu [128.227.100.198] in the file pub/perl/doc/FAQ, as well as on rtfm.mit.edu [18.181.0.24] in /pub/usenet/comp.lang.perl.*. If you have any suggested additions or corrections to this article, please send them to .


General Information and Availability


1.1) What is Perl?
1.2) What are perl4 and perl5, are there any differences?
1.3) What features does perl5 provide over perl4?
1.4) Where can I get docs on perl5?
1.5) Will perl5 break my perl4 scripts?
1.6) When will Perl stabilize?
1.7) What's the difference between "perl" and "Perl"?
1.8) Is it a perl program or a perl script?
1.9) Is perl difficult to learn?
1.10) Should I program everything in perl?
1.11) How does perl compare with other scripting languages, like Tcl, Python or REXX?
1.12) Where can I get Perl over the Internet (FTP)?
1.13) How can I get Perl via email?
1.14) How can I get Perl via UUCP?
1.15) Are there other ways of getting perl?
1.16) Has perl been ported to machine FOO?
1.17) How do I get perl to compile on Solaris?
1.18) How do I get perl to compile on a NeXT?
1.19) What extensions are available for Perl and where can I get them?
1.20) What is dbperl and where can I get it?
1.21) Which DBM should I use?
1.22) Is there an SNMP aware perl?
1.23) Is there an ISO or ANSI certified version of Perl?

1.1) What is Perl?

Perl is a compiled scripting language written by Larry Wall*.

Here's the beginning of the description from the perl(1) 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. OK, enough hype.

1.2) What are perl4 and perl5, are there any differences?

Perl4 and perl5 are different versions of the language. Perl4 was the previous release, and perl5 is ``Perl: The Next Generation.'' Perl5 is, essentially, a complete rewrite of the perl source code from the ground up. It has been modularized, object oriented, tweaked, trimmed, and optimized until it almost doesn't look like the old code. However, the interface is mostly the same, and compatibility with previous releases is very high.

1.3) What features does perl5 provide over perl4?

If you get the newest source (from any of the main FTP sites), you will find a directory full of man pages (possibly to be installed as section 1p and 3pm) that discuss the differences, new features, old incompatibilies and much more. Here, however, are some highlights as to the new features and old incompatibilities. (Thanks to Tom Christiansen* for this section)

1.4) Where can I get docs on perl5?

The complete perl documentation is available with the Perl distribution, or can be accessed from the following sites. Note that the PerlDoc ps file is 240 pages long!!
Marked Up (HTML) format:
http://www.metronet.com/0/perlinfo/perl5/manual/perl.html
http://web.nexor.co.uk/perl/perl.html                       (Europe)
    
PostScript:
ftp://ftp.cis.ufl.edu/pub/perl/doc/PerlDoc.ps.gz
ftp://ftp.uu.net/languages/perl/PerlDoc.ps.gz
ftp://www.metronet.com/pub/perl/perl5/manual/PerlDoc.ps.gz
ftp://ftp.zrz.tu-berlin.de/pub/unix/perl/PerlDoc.ps.gz  (Europe)
ftp://ftp.cs.ruu.nl/pub/PERL/perl5.0/doc/PerlDoc.ps.gz  (Europe)
ftp://sungear.mame.mu.oz.au/pub/perl/doc/PerlDoc.ps.gz  (Oz)
        unable to access as of 7/15/95
TeXinfo (Emacs) Format:
ftp://www.metronet.com/pub/perl/perl5/manual/perl5-info.tar.gz
    

1.5) Will perl5 break my perl4 scripts?

In general, no. However, certain bad old practices have become highly frowned upon. The following are the most important of the known incompatibilities between perl4 and perl5. See perltrap(1) for more details.

1.6) When will Perl stabilize?

When asked at what point the Perl code would be frozen, Larry answered:
Part of the redesign of Perl is to allow us to more or less freeze the language itself. It won't totally freeze, of course, but I think the rate of change of the core of the language is asymptotically approaching 0. In fact, as time goes on, now that we have an official extension mechanism, some of the things that are currently in the core of the language may move out (transparently) as extensions. This has already happened to dbmopen().

I've also been continuously reminding myself of what Henry Spencer calls ``second system syndrome'', in which everything under the sun gets added, resulting in a colossal kludge, like OS 360. You'll find that the new features in Perl 5 are all pretty minimalistic. The object-oriented features in particular added only one new piece of syntax, a C++-style method call.

The whole idea behind Perl is to be a fast text-processing, system-maintenance, zero-startup time language. If it gets to be so large and complicated that it isn't fast-running and easy to use, it won't be to anyone's benefit.
My motto from the start has been, ``If it ain't broke, don't fix it.'' I've been trying very hard not to remove those features from Perl that make it what it is. At the same time, a lot of streamlining has gone into the syntax. The new yacc file is about half the size of the old one, and the number of official reserved words has been cut by 2/3. All built-in functions have been unified (dualified?) as either list operators or unary operators.
I really like a lot of the features in Perl, but in order for Perl to be useful on a long term basis, those features have to stay put. I bought the Camel book less than a year ago and it sounds like within another year it will be obsolete.
The parts of Perl that the Camel book covers have not changed all that much. Most old scripts still run. Many scripts from Perl version 1.0 still run. We'll certainly be revising the Camel, but the new man pages are split up such that it's pretty easy to ferret out the new info when you want it.

We did break a few misfeatures in going to Perl 5. It seemed like the first and last chance to do so. There's a list of the incompatibilities in the documentation.

Not only is it a lot of work to recompile Perl on 20+ machines periodically, but it's hard to write scripts that are useful in the long term if the guts of the language keep changing. (And if I keep having to buy new books. I keep hearing about new features of Perl 5 that aren't documented in any of the perl 5 documentation that I can find.)
I think you'll find a lot of folks who think that 4.036 has been a pretty stable platform.

Perl 5 is a special case. I've been working on it for years. (This is part of the reason 4.036 has been so stable!) There are many changes, most of them for the better, I hope. I don't expect the transition to be without pain. But that's why I stuck numbered versions out in your bin directory, so that you can upgrade piecemeal if you like. And that's why I made the -w switch warn about many of the incompatibilities.

And overriding all that, I've tried to keep it so that you don't have to know much about the new stuff to use the old stuff. You can upgrade your knowledge piecemeal too.

The extension mechanism is designed to take over most of the evolutionary role from now on. And it's set up so that, if you don't have a particular extension, you know it right up at the front.

Are there any plans to write a Perl compiler? While interpreted Perl is great for many applications, it would also be cool to be able to precompile many scripts. (Yes, I know you can undump things, but undump isn't provided with Perl and I haven't found a copy.) The creation of a perl library and dynamically-loadable modules seems like a step in that direction.
Yes, part of the design of Perl 5 was to make it possible to write a compiler for it. It could even be done as an extension module, I suppose. Anyone looking for a master's thesis topic?

In summary, almost every concern that you might think of has already been (at least) thought about. In a perfect world, every concern could be addressed perfectly. But in this world we just have to slog through.

1.7) What's the difference between ``perl'' and ``Perl''?

    32!  [ ord('p') - ord('P') ]
    

Larry now uses ``Perl'' to signify the language proper and ``perl'' the implementation of it, i.e. the current interpreter. Hence Tom's quip that ``Nothing but perl can parse Perl.''

On the other hand, the aesthetic value of casewise parallelism in ``awk'', ``sed'', and ``perl'' as much require the lower-case version as ``C'', ``Pascal'', and ``Perl'' require the upper-case version. It's also easier to type ``Perl'' in typeset print than to be constantly switching in Courier. :-)

In other words, it doesn't matter much, especially if all you're doing is hearing someone talk about the language; case is hard to distinguish aurally.

1.8) Is it a perl program or a perl script?

It depends on whether you are talking about the perl binary or something that you wrote using perl. And, actually, even this isn't necessarily true.

``Standard'' UNIX terminology is (roughly) this: programs are compiled into machine code once and run multiple times, scripts are translated (by a program) each time they are used. However, some say that a program is anything written which is executed on a computer system. Larry considers it a program if it is set in stone and you can't change it, whereas if you can go in and hack at it, it's a script. Of course, if you have the source code, that makes just about anything a script. ;)

In general, it probably doesn't really matter. The terms are used interchangeably. If you particularly like one or the other, use it. If you want to call yourself a perl programmer, call them programs. If you want to call yourself a perl scripter, call them scripts. Randal* and I (at least) will call them hacks. (See question 2.10 ;)

Larry says that a script is what you give an actor, but a program is what you give an audience.

1.9) Is perl difficult to learn?

Not at all. Many people find Perl extremely easy to learn. There are at least three main reasons for this.

The first reason is that most of Perl has been derived from standard utilities, tools, and languages that you are (probably) already familiar with. If you have any knowledge of the C programming language and standard C library, the Unix Shell, sed and awk, Perl should be simple and fun for you to learn.

The second reason that Perl is easy to learn is that you only have to know a very small subset of Perl to be able to get useful results. In fact, once you can master

    #!/usr/local/bin/perl
    print "Hello, world\n";
you can start writing Perl scripts. In fact, you will probably never have to (or be able to) know everything about Perl. As you feel the need or desire to use more sophisticated features (such as C structures or networking), you can learn these as you go. The learning curve for Perl is not a steep one, especially if you have the headstart of having a background in UNIX. Rather, its learning curve is gentle and gradual, but it is admittedly rather long.

The third reason is that you can get immediate results from your scripts. Unlike a normal compiled language (like C or Pascal, for example), you don't have to continually recompile your program every time you change one little thing. Perl allows you to experiment and test/debug quickly and easily. This ease of experimentation flattens the learning curve even more.

If you don't know C or UNIX at all, it'll be a steeper learning curve, but what you then learn from Perl will carry over into other areas, like using the C library, UNIX system calls, regular expressions, and associative arrays, just to name a few. To know Perl is to know UNIX, and vice versa.

1.10) Should I program everything in Perl?

Most definitely. In fact, you should delete the binaries for sed, awk, cc, gcc, grep, rm, ls, cat... well, just delete your /bin directory.

But seriously, of course you shouldn't. As with any job, you should use the appropriate tool for the task at hand. Just because a hammer will put screws into a piece of board, you probably don't want to do that.

While it's true that the answer to the question ``Can I do (some arbitrary task) in Perl?'' is almost always ``yes'', that doesn't mean this is necessarily a good thing to do. For many people, Perl serves as a great replacement for shell programming. For a few people, it also serves as a replacement for most of what they'd do in C. But for some things, Perl just isn't the optimal choice.

1.11) How does Perl compare with other scripting languages, like Tcl, Python or REXX?

REXX is an interpreted programming language first seen on IBM systems. Python is an interpreted programming language by Guido van Rossum*. TCL is John Ousterhout*'s embeddable command language, designed just for embedded command extensions, but lately used for larger applications. TCL's most intriguing feature for many people is the tcl/tk toolset that allows for interpreted X-based tools. Others use it for its ``expect'' extension.

To avoid any flamage, if you really want to know the answer to this question, probably the best thing to do is try to write equivalent code to do a set of tasks. All three have their own newsgroups in which you can learn about (but hopefully not argue about) these languages.

To find out more about these or other languages, you might also check out David Muir Sharnoff*'s posting ``Catalog of Compilers, Interpreters, and Other Language Tools'' which he posts to comp.lang.misc, comp.sources.d, comp.archives.admin, and news.answers newsgroups. It's a comprehensive treatment of many different languages. (Caveat lector: he considers Perl's syntax ``unappealing''.)

1.12) How can I get Perl over the Internet?

Perl is available from any comp.sources.misc archive. You can use an archie server (see the alt.sources FAQ in news.answers) to find these if you want.

Version 4:
Volume  Issues  Patchlevel and Notes
------  ------  ------------------------------------------------
  18    19-54   Patchlevel 3, Initial posting.
  20    56-62   Patches 4-10

Version 5:
Volume  Issues  Patchlevel and Notes
------  ------  -----------------------------------------------
  45    64-128  Initial Posting, patchlevel 0.
Since 1993, a number of archives have sprung up specifically for Perl and Perl related items. Larry maintains the official distribution site (for both perl4.036 and perl5) at netlabs. Probably the largest archive is at the University of Florida. In order of probability these sites will have the sources.

Site    Directory and notes                         IP
---------------------------------------------       -------

North America:
ftp://ftp.netlabs.com/pub/outgoing/perl5.0/         192.94.48.152
ftp://ftp.cis.ufl.edu/pub/perl/src/5.0/             128.227.100.198
ftp://prep.ai.mit.edu/pub/gnu/                      18.71.0.38
        not current as of 7/15/95
ftp://ftp.uu.net/languages/perl/                    192.48.96.9
        not current as of 7/15/95
ftp://ftp.khoros.unm.edu/pub/perl/                  198.59.155.28
        not current as of 7/15/95
ftp://ftp.cbi.tamucc.edu/pub/duff/Perl/             165.95.1.3
ftp://ftp.metronet.com/pub/perl/sources/            192.245.137.1
ftp://genetics.upenn.edu/perl5/                     128.91.200.37

Europe:
ftp://ftp.cs.ruu.nl/pub/PERL/perl5.0/src/           131.211.80.17
ftp://ftp.funet.fi/pub/languages/perl/ports/perl5/  128.214.248.6
ftp://ftp.zrz.tu-berlin.de/pub/unix/perl/           130.149.4.40
ftp://src.doc.ic.ac.uk/packages/perl5/              146.169.17.5

Australia:
ftp://sungear.mame.mu.oz.au/pub/perl/src/5.0/       128.250.209.2

South America (mirror of ftp://prep.ai.mit.edu/pub/gnu):
ftp://ftp.inf.utfsm.cl/pub/gnu/                     146.83.198.3

If there is a site in Asia or Japan, please tell us about it. Thanks!

You can also retrieve perl via non-ftp methods:

http://src.doc.ic.ac.uk/packages/perl5/             146.169.17.5
gopher://src.doc.ic.ac.uk/0/packages/perl5/         146.169.17.5

1.13) How can I get Perl via Email?

The following is a list of known ftpmail sites. Please attempt to use the site closest to you with the ftp archive closest to it. Many of these sites already have perl on them. For information on how to use one of these sites, send email containing the word ``help'' to the address.

    United States:
	Massachusetts:      ftpmail@decwrl.dec.com
	New Jersey:         bitftp@pucc.princeton.edu
	North Carolina:     ftpmail@sunsite.unc.edu

    Europe/UK:
	Germany:            ftpmail@ftp.uni-stuttgart.de
			    bitftp@vx.gmd.de
	UK:                 ftpmail@doc.ic.ac.uk

    Australia:              ftpmail@cs.uow.edu.au
Henk P Penning* suggests that if you are in Europe you should try the following (if you are in Germany or the UK, you should probably use one of the servers listed above):
    Email: Send a message to 'mail-server@cs.ruu.nl' containing:
     begin
     path your_email_address
     send help
     send PERL/perl5.0/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.

If all else fails, mail to Larry usually suffices.

1.14) How can I get Perl via UUCP?

There currently is no way of getting Perl via UUCP. If anyone knows of a way, please contact me. The OSU site has discontinued the service.

1.15) Are there other ways of getting perl?

Another possibility is to use UUNET, although they charge you for it. You have been duly warned. Here's the advertisement:

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!/info/help contains instructions. The file uunet!/index//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)
info@uunet.uu.net

1.16) Has perl been ported to machine FOO?

Perl runs on virtually all Unix machines simply by following the hints file and instructions in the Configure script. This auto-configuration script allows Perl to compile on a wide variety of platforms by modifying the machine specific parts of the code. For most Unix systems, or VMS systems for v5 perl, no porting is required. Try to compile Perl on your machine. If you have problems, examine the README file carefully. If all else fails, send a message to comp.lang.perl.misc and crosspost to comp.sys.[whatever], there's probably someone out there that has already solved your problem and will be able to help you out.

Perl4.036 has been ported to many non-Unix systems, although currently there are only a few (beta) v5 ports. All of the following are mirrored at ftp://ftp.cis.ufl.edu:/pub/perl/src/. The following are the (known) official distribution points. Please contact the porters directly (when possible) in case of questions on these ports.

1.17) How do I get Perl to compile on Solaris?

The following directions are for perl, version 4. Perl, version 5, should compile more easily. If not, send mail to The Perl Porters Mailing List (perl5-porters@nicoh.com)

John Lees* reports:

I have built perl on Solaris 2.1, 2.2 beta, and 2.2 FCS. Take /usr/ucb out of your path and do not use any BSD/UCB libraries. Only -lsocket, -lnsl, and -lm are needed. You can use the hint for Solaris 2.0, but the one for 2.1 is wrong. Do not use vfork. Do not use -I/usr/ucbinclude. The result works fine for me, but of couse does not support a couple of BSDism's.

Casper H.S. Dik* reports

You must remove all the references to /usr/ucblib AND /usr/ucbinclude. And ignore the Solaris_2.1 hints. They are wrong. The undefining of vfork() probably has to do with the confusion it gives to the compilers. If you use cc, you mustn't compile util.c/tutil.c with -O. I only used the following libs: -lsocket -lnsl -lm (there is a problem with -lmalloc)

Michael D'Errico* reports:

If you are using Solaris 2.x, the signal handling is broken. If you set up a signal handler such as 'ripper' it will be forgotten after the first time the signal is caught. To fix this, you need to recompile Perl. Just add '#define signal(x,y) sigset((x),(y))' after the '#include ' directive in each file that it occurs, then make it again.

1.18) How do I get Perl to compile on a Next?

According to Andreas Koenig*, under NeXTstep 3.2, both perl4.036 and perl5.000 compile with the supplied hints file.

However, Bill Eldridge* provides this message to help get perl4.036 on NeXTstep 3.0 to work:

To get perl to compile on NeXTs, you need to combine the ANSI and BSD headers:

    cd /usr/include
    mkdir ansibsd
    cd ansibsd
    ln -s ../ansi
    ln -s ../bsd

Then, follow the configuration instructions for NeXTs, replacing all mention of -I/usr/include/ansi or -I/usr/include/bsd with -I/usr/include/ansibsd.

1.19) What extensions are available from Perl and where can I get them?

Some of the more popular extensions include those for windowing, graphics, or data base work. Most of the major sites contain an archive of the extensions, usually in the ext directory. Since the list of available extensions changes so often, I have opted to list only the sites and directories, not the individual extensions, please check the closest archive for more information

1.20) What is dbperl and where can I get it?

Many database-oriented extensions to Perl have been written. Basically, these use the usub mechanism (see the usub/ subdirectory) in the source distribution) to link in a database library, allowing embedded calls to Informix, Ingres, Interbase, Oracle and Sybase.

Here are the authors of the various extensions:

What            Target DB       Who
--------        -----------     ----------------------------------------
?Infoperl       Informix        Kurt Andersen (kurt@hpsdid.sdd.hp.com)
Ingperl         Ingres          Tim Bunce (timbo@ig.co.uk) and Ted Lemon
Interperl       Interbase       Buzz Moschetti (buzz@bear.com)
Isqlperl        Informix        William Hails bill@tardis.co.uk
Oraperl         Oracle          Kevin Stock (kstock@Auspex.com)
Pgperl          Postgres        Igor Metz (metz@iam.unibe.ch)
*Sqlperl        Ingres          Ted Lemon (mellon@ncd.com)
Sybperl         Sybase          Michael Peppler (mpeppler@itf.ch)
Uniperl         Unify 5.0       Rick Wargo (rickers@coe.drexel.edu)

    ? Does this one still exist?
    
*Sqlperl appears to have been subsumed by Ingperl

Buzz Moschetti* has organized a project to create a higher level interface to allow you to write your queries in a database-independent fashion. If this type of project interests you, send mail to <perldb-interest-request@vix.com> and asked to be placed on the ``perldb-interest'' mailing lists.

Here's a bit of advertising from Buzz:

Perl is an interpreted language with powerful string, scalar, and array processing features developed by Larry Wall that ``nicely bridges the functionality gap between sh(1) and C.'' Since relational DB operations are typically textually oriented, perl is particularly well-suited to manage the data flows. The C source code, which is available free of charge and runs on many platforms, contains a user-defined function entry point that permits a developer to extend the basic function set of the language. The DBperl Group seeks to exploit this capability by creating a standardized set of perl function extensions (e.g. db_fetch(), db_attach()) based on the SQL model for manipulating a relational DB, thus providing a portable perl interface to a variety of popular RDMS engines including Sybase, Oracle, Ingres, Informix, and Interbase. In theory, any DB engine that implements a dynamic SQL interpreter in its HLI can be bolted onto the perl front end with predicatable results, although at this time backends exist only for the aforementioned five DB engines.

The official archive for DBperl extensions is ftp://ftp.demon.co.uk/pub/perl/db It's the home of the evolving DBperl API Specification. Here's an extract from the updated README there:


DBI/        The home of the DBI archive. To join the DBI mailing list
	    send your request to perldb-interest-REQUEST@vix.com

DBD/        Database Drivers for the DBI ...

Oracle/      By Tim Bunce (not yet ready!)
Ingres/      By Tim Bunce (not yet started!)

mod/           Other Perl 5 Modules and Extensions ...

Sybperl/    By Michael Peppler, mpeppler@itf.ch

perl4/         Perl 4 extensions (using the usub C interface)

   oraperl/   ORACLE 6 & 7  By Kevin Stock, kstock@auspex.com
   sybperl/   SYBASE 4      By Michael Peppler, mpeppler@itf.ch
   ingperl/   INGRES        By Tim Bunce timbo@ig.co.uk and Ted Lemon
   isqlperl/  INFORMIX      By William Hails, bill@tardis.co.uk
   interperl/ INTERBASE     By Buzz Moschetti, buzz@bear.com
   oraperl/   ORACLE 6 & 7  By Kevin Stock (sadly no longer on the net)
   sybperl/   SYBASE 4      By Michael Peppler, mpeppler@itf.ch
   ingperl/   INGRES        By Tim Bunce timbo@ig.co.uk and Ted Lemon
   isqlperl/  INFORMIX      By William Hails, bill@tardis.co.uk
   interperl/ INTERBASE     By Buzz Moschetti, buzz@bear.com
   uniperl/   UNIFY 5.0     By Rick Wargo, rickers@coe.drexel.edu
   pgperl/    POSTGRES      By Igor Metz, metz@iam.unibe.ch

   btreeperl/ NDBM perl extensions.   By John Conover, john@johncon.com
   ctreeperl/ C-Tree perl extensions. By John Conover, john@johncon.com
   duaperl/   X.500 Directory User Agent. By Eric Douglas.

scripts/       Perl and shell scripts

   rdb/       RDB is a perl RDBMS for ASCII files. By Walt Hobbs,
		hobbs@rand.org
   shql/      SHQL is an interactive SQL database engine.  Written as a
		shell script, SHQL interprets SQL commands and
		manipulates flat files based on those commands. By
		Bruce Momjian, root@candle.uucp
   xbase/     Perl scripts for accessing xBase style files (dBase III)

refinfo/       Reference information

   sqlsyntax/ Yacc and lex syntax and C source code for SQL1 and SQL2
	from ftp.uu.net:/pub/uunet/published/oreilly/nutshell/yacclex,
	and a draft SQL3 syntax from Jeff Fried <jfried@informix.com>+
   formats/   Details of file formats such as Lotus 1-2-3 .WK1

There are also a number of non SQL database interfaces for perl available from ftp.demon.co.uk. These include:

Directory   Target System   Authors and notes
---------   -------------   -------------------------------------------
btreeperl   NDBM extension  John Conover (john@johncon.com)
ctreeperl   CTree extension John Conover (john@johncon.com)
duaperl     X.500 DUA       Eric Douglas
rdb         RDBMS           Walt Hobbs (hobbs@rand.org)
shql        SQL Engine      Bruce Momjian (root@candle.uucp)

1.21) Which DBM should I use?

As shipped, Perl (version 5) comes with interfaces for several DBM packages (SDBM, old DBM, NDBM, GDBM, Berkeley DBM) that are not supplied but either come with your system are readily accessible via FTP. SDBM is guaranteed to be there. For a comparison, see AnyDBM_File(3pm) and DB_File(3pm) .

1.22) Is there an SNMP aware Perl?

snmperl was written by Guy Streeter (streeter@ingr.com), and was posted in late February 1993 to comp.protocols.snmp. It can be found archived at one of two (known) places:

Host liasun3.epfl.ch
Location: /pub/net/snmp
       FILE -rw-rw-r--       3407  Aug 11 1992  snmperl.README
       FILE -rw-r--r--      17678  Aug 11 1992  snmperl.tar.Z

Host ftp.cis.ufl.edu
Location: /pub/perl/scripts/snmp

Here is the gist of the README:

This directory contains the source code to add callable C subroutines to perl. The subroutines implement the SNMP functions ``get'', ``getnext'', and ``set''. They use the freely-distributable SNMP package (version 1.1b) from CMU.

USE: There are four subroutines defined in the callable interface: snmp_get, snmp_next, snmp_set, and snmp_error.

snmp_get and snmp_next implement the GET and GETNEXT operations, respectively. The first two calling arguments are the hostname and Community string. The IP address of the host, as a dotted-quad ASCII string, may be used as the hostname. The rest of the calling arguments are a list of variables. See the CMU package documentation for how variables may be specified.

snmp_set also takes hostname and Community string as arguments. The remaining arguments are a list of triples consisting of variable name, variable type, and value. The variable type is a string, such as ``INTEGER'' or ``IpAddress''.

snmp_get, snmp_next, and snmp_set return a list containing alternating variables and values. snmp_get and snmp_next will simply omit non-existent variables on return. snmp_set will fail completely if one of the specified variables does not exist (or is read-only).

snmp_error will return a text string containing some error information about the most recent snmp_get|next|set call, if it had an error.

OTHER NOTES:
I didn't find all the places where the CMU library writes to stderr or calls exit() directly.

The changes I made to mib.c involve the formatting of variable values for return to the caller. I took out the descriptive prefix so the string contains only the value.

Enumerated types are returned as a string containing the symbolic representation followed in parentheses by the numeric.

DISTRIBUTION and OWNERSHIP

perl and the CMU SNMP package have their own statements. Read them. The work I've done is free and clear. Just don't say you wrote it if you didn't, and don't say I wrote it if you change it.

    Guy Streeter
    streeter@ingr.com
    April 1, 1992 (not a joke!)

1.23) Is there an ISO or ANSI certified version of Perl?

No. Larry thinks it likely that he'll be certified before perl is.

Informational Sources


2.1) Is there a USENET group for perl?
2.2) Have any books or magazine articles been published about perl?
2.3) When will the Camel and Llama books be updated?
2.4) What FTP resources are available?
2.5) What WWW/gopher resources are available?
2.6) Can people who don't have access to USENET get comp.lang.perl.misc?
2.7) Are archives of comp.lang.perl.* available?
2.8) Is there a WAIS server for comp.lang.perl.*?
2.9) What other sources of information about Perl or training are available?
2.10) Where can I get training classes on Perl?
2.11) What companies ship or use perl?
2.12) Is there commercial, third-party support for perl?
2.13) What is a JAPH? What does "Will hack perl for ..." mean?
2.14) Where can I get a collection of Larry Wall witticisms?
2.15) What are the known bugs?
2.16) Where should I post bugs?
2.17) Where should I post source code?
2.18) Where can I learn about object-orienting Perl programming?
2.19) Where can I learn about linking C with Perl? [h2xs, xsubpp]
2.20) What is perl.com?
2.21) What do the asterisks (*) throughout the FAQ stand for?

2.1) Is there a USENET group for Perl?

Yes there is: comp.lang.perl.misc. This group, which currently can get up to 150 messages per day, contains all kinds of discussions about Perl; everything from bug reports to new features to the history to humour and trivia. This is the best source of information about anything Perl related, especially what's new with Perl5. Because of its vast array of topics, it functions as both a comp.lang.* style newsgroup (providing technical information) and also as a rec.* style newsgroup, kind of a support group for Perl addicts (PerlAnon?). There is also the group comp.lang.perl.announce, a place specifically for announcements related to perl (new releases, the FAQ, new modules, etc).

Larry is a frequent poster to this group as well as most (all?) of the seasoned Perl programmers. Questions will be answered by some of the most knowledgable Perl Hackers, often within minutes of a question being posted (give or take distribution times).

2.2) Have any books or magazine articles been published about Perl?

There are a number of books either available or planned. Mostly chronologically, they are:

Programming Perl (the ``Camel Book''):

Author: Larry Wall and Randal Schwartz
Publisher: O'Reilly and Associates
ISBN 0-937175-64-1 (English)
ISBN 4-89052-384-7 (Japanese)
ISBN 3-446-17257-2 (German) (Programmieren in Perl)
(translator: Hanser Verlag)

This is probably the most well known and most useful book for 4.036 and earlier. This part of O'Reilly's hugely successful ``Nutshell Handbook'' series. Besides serving as a reference guide for Perl, it also contains tutorial material and 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 from ftp://ftp.ora.com/pub/examples/nutshell/programming_perl/perl.tar.Z or ftp://ftp.cis.ufl.edu/pub/perl/ora/programming_perl. Corrections and additions to the book can be found in the Perl4 man page right before the BUGS section under the heading ERRATA AND ADDENDA.

Learning Perl (the ``Llama Book''):

Another of O'Reilly's ``Nutshell Handbooks'', by Randal Schwartz. This book is a smaller, gentler introduction to perl and is based off of Randal's perl classes. While in general this is a good book for learning perl (like its title), early printings did contain many typos and don't cover some of the more interesting features of perl. Please check the errata sheet at ftp.ora.com, as well as the on-line examples. If you can't find these books in your local technical bookstore, they may be ordered directly from O'Reilly by calling 1-800-998-9938 if in North America and 1-707-829-0515 otherwise.

Johan Vromans* created a beautiful reference guide. The reference guide comes with the Camel book in a nice, glossy format. The LaTeX (source) and PostScript (ready to print) versions are available for FTP from ftp.cs.ruu.nl:/pub/DOC/perlref-4.036.1.tar.Z in Europe or from ftp.cis.ufl.edu:/pub/perl/doc/perlref-4.036.tar.gz in the United States. Obsolete versions in TeX or troff may still be available, but these versions don't print as nicely. See also:

Johan has also updated and released a reference guide based on version 5.000. This is available from the same places as the 4.036 guide. This version is also available from prep.gnu.ai.mit.edu in the /pub/gnu section along with the perl5 source. It may be added to the standard perl5 distribution sometime after 5.002. If you are using version 5.000, you will want to get this version rather than the 4.036 version.

Larry routinely carries around a camel stamp to use when autographing copies of his book. If you can catch him at a conference you can usually get him to sign your book for you.

Prentice Hall also has two perl books.

The first is Perl by Example by Ellie Quigley. (385 pages, $26.96, ISBN 0-13-122839-0) A perl tutorial (perl4); every feature is presented via an annotated example and sample output. Reviews of this book have varied widely. Many new perl users have used this book with much success, while many ``veteran'' programmers have had many complaints about it.

The second book is called Software Engineering with Perl by Carl Dichter and Mark Pease. Randal Schwartz was a technical reviewer for this book and notes this:

SEwP is not meant as instruction in the Perl language, but rather as an example of how Perl may be used to assist in the semi-formal software engineering development cycles. There's a lot of Perl code that's fairly well commented, but most of the book describes software engineering methodologies. For the perl-challenged, there's a light treatment of the language as well, but they refer to the llama and the camel for the real meat.

SAMS Publishing also has a Perl book available, as part of their ``Teach Yourself in 21 Days'' series, called Teach Yourself Perl in 21 Days. ISBN 0-672-30586-0 Price: $29.95, 841 Pages. This book is the first book to have a section devoted to version 5.000, although it was written during an alpha stage and may not necessarily reflect current reality.

Please note that none of the above books are perfect, all have some inaccurances and typos. The two which Larry is directly associated with (the O'Reilly books) are probably the most technically correct, but also the most dated. Carefully looking over any book you are considering purchasing will save you much time, money, and frustration.

Starting in the March, 1995 edition of Unix Review. Randal Schwartz* has been authoring a bi-monthly Perl column. This has so far been an introductory tutorial.

Larry Wall has published a 3-part article on perl in Unix World (August through October of 1991), and Rob Kolstad also had a 3-parter in Unix Review (May through July of 1990). Tom Christiansen also has a brief overview article in the trade newsletter Unix Technology Advisor from November of 1989. You might also investigate ``The Wisdom of Perl'' by Gordon Galligher from SunExpert magazine; April 1991 Volume 2 Number 4. The Dec 92 Computer Language magazine also contains a cover article on Perl, ``Perl: the Programmers Toolbox''.

Many other articles on Perl have been recently published. If you have references, especially on-line copies, please mail them to the FAQ maintainer for inclusion is this notice.

The USENIX LISA (Large Installations Systems Administration) Conference have for several years now included many papers of tools written in Perl. Old proceedings of these conferences are available; look in your current issue of ``;login:'' or send mail to office@usenix.org for further information.

Japan seems to be jumping with Perl books. If you can read japanese here are a few you might be interested in. Thanks to Jeffrey Friedl* and Ken Lunde* for this list (NOTE: my screen cannot handle japanese characters, so this is all in English for the moment NOTE2: These books are written in Japanese, these titles are just translations):


Title: Welcome to Perl Country	(Perl-no Kuni-he Youkoso)
Authors: Kaoru Maeda, Hiroshi Koyama, Yasushi Saito and Arihito
	 Fuse
Pages: 268+9	    	    	Publisher: Science Company	
Pub. Date: April 25, 1993   	ISBN: 4-7819-0697-4 		
Price: 2472Y	    	    	Author Email: maeda@src.ricoh.co.jp
Comments: Written during the time the Camel book was being 
translated.  A useful introduction, but uses jperl (Japanese Perl)
which is not necessarily compatible.

Title: How to Write Perl (Perl Shohou) Author: Toshiyuki Masui Pages: 352 Publisher: ASCII Corporation Pub. Date: July 1, 1993 ISBN: 4-7561-0281-6 Price: 3200Y Author Email: masui@shocsl.sharp.co.jp Comments: More advanced than ``Welcome..'' and not meant as an introduction. Uses the standard perl and has examples for handling Japanese text.

Title: Introduction to Perl (Nyuumon Perl) Author: Shinji Kono Pages: 203 Publisher: ASCII Corporation Date: July 11, 1994 ISBN: 4-7561-0292-1 Price: 1800Y Author Email: kono@csl.sony.co.jp Comments: Uses the interactive Perl debugger to explain how things work.

Title: Perl Programming Authors: L Wall & R Schwartz Translator: Yoshiyuki Kondo Pages: 637+32 Publisher: Softbank Corporation Pub. Date: February 28, 1993 ISBN: 4-89052-384-7 Price: 4500Y Author Email: cond@lsi-j.co.jp Comments: Official Japanese translation of the Camel book, ``Programming Perl''. Somewhat laced with translator notes to explain the humour. The most useful book. Also includes the Perl Quick Reference -- in Japanese!

2.3) When will the Camel and Llama books be updated?

As of August, 1995, ORA has contracted with Stephen to handle the Camel update. According to the accepted timeline, the first draft is to be finished by the end of April, 1996. The tutorial sections are being cut some, and the book will take on much more of a reference style. Don't worry, it will still contain its distinctive humor and flair.

There are no current plans to update the Llama. For the most part, it serves as a good introduction for both major versions of perl. There may be some minor editing to it, but probably nothing major. If anything, it is more likely that a third book (working title: Learning More Perl) will be written as a tutorial for the new perl5 paradigm.

2.4) What FTP resources are available?

Since 1993, several ftp sites have sprung up for Perl and Perl related items. The site with the biggest repository of Perl scripts right now seems to be ftp.cis.ufl.edu [128.227.100.198] in /pub/perl. The scripts directory has an INDEX with over 400 lines in it, each describing what the script does. The src directory has sources and/or binaries for a number of different perl ports, including MS-Dos, Macintosh and Windows/NT. This is maintained by the Computing Staff at UF*.

Note: European users please use the site src.doc.ic.ac.uk [149.169.2.1] in /pub/computing/programming/languages/perl/ The link speed would be a lot better for all. Contact L.McLoughlin@doc.ic.ac.uk for more information. It is updated daily.

There are also a number of other sites. I'll add more of them as I get information on them. [site maintainers: if you want to add a blurb here, especially if you have something unique, please let me know. -spp]

The Comprehensive Perl Archive Network (CPAN) is in heavy development. Once the main site and its mirrors are fully operational, this answer will change to reflect its existence.

2.5) What WWW/gopher resources are available?

The World Wide Web is exploding with new Perl sites all the time. Some of the more notable ones are: http://www.cis.ufl.edu/perl http://www.metronet.com/1h/perlinfo, which has a great section on Perl5. http://www.eecs.nwu.edu/perl/perl.html http://web.nexor.co.uk/perl/perl.html, a great site for European and UK users.

2.6) Can people who don't have access to USENET get comp.lang.perl.misc?

``Perl-Users'' is the mailing list version of the comp.lang.perl.misc newsgroup. If you're not lucky enough to be on USENET you can post to comp.lang.perl.misc by sending to one of the following addresses. Which one will work best for you depends on which nets your site is hooked into. Ask your local network guru if you're not certain.

Internet
PERL-USERS@VIRGINIA.EDU
Perl-Users@UVAARPA.VIRGINIA.EDU
BitNet
Perl@Virginia
uucp
...!uunet!virginia!perl-users

The Perl-Users list is bidirectionally gatewayed with the USENET newsgroup comp.lang.perl.misc. This means that VIRGINIA functions as a reflector. All traffic coming in from the non-USENET side is immediately posted to the newsgroup. Postings from the USENET side are periodically digested and mailed out to the Perl-Users mailing list. A digest is created and distributed at least once per day, more often if traffic warrants.

All requests to be added to or deleted from this list, problems, questions, etc., should be sent to:

Internet
Perl-Users-Request@Virginia.EDU
Perl-Users-Request@uvaarpa.Virginia.EDU
BitNet
Perl-Req@Virginia
uucp
...!uunet!virginia!perl-users-request
Coordinator
Marc Rouleau <mer6g@VIRGINIA.EDU>

2.7) Are archives of comp.lang.perl.misc available?

Yes, there are. ftp.cis.ufl.edu:/pub/perl/comp.lang.perl.*/monthly has an almost complete collection dating back to 12/89 (missing 08/91 through 12/93). They are kept as one large file for each month.

A more sophisticated query and retrieval mechanism is desirable. Preferably one that allows you to retrieve article using a fast-access indices, keyed on at least author, date, subject, thread (as in ``trn'') and probably keywords. Right now, the MH pick command works for this, but it is very slow to select on 18000 articles.

If you have, or know where I can find, the missing sections, please let perlfaq@perl.com know.

2.8) Is there a WAIS server for comp.lang.perl.*?

Yes there is. Set your WAIS client to archive.orst.edu:9000/comp.lang.perl.*. According to their introduction, they have a complete selection from 1989 on.

Bill Middleton <wjm@feenix.metronet.com> offers this:

I have setup a perl script retrieval service and WaisSearch here at feenix. To check it out, just point your gopher at us, and select the appropriate menu option. The WaisSearch is of the iubio type, which means you can do boolean searching. Thus you might try something like:
caller
ioctl and fcntl
grep and socket not curses

and other things to see examples of how other folks have done this or that. This service is still under construction, but I'd like to get feedback, if you have some time.

There's also a WaisSearch into all the RFC's and some other fairly nifty stuff.

2.9) What other sources of information about Perl or training are available?

There is a #Perl channel on IRC (Internet Relay Chat) where Tom and Randal have been known to hang out. Here you can get immediate answers to questions from some of the most well-known Perl Hackers.

The perl5-porters (perl5-porters@nicoh.com) mailing list was created to aid in communication among the people working on perl5. However, it has overgrown this function and now also handles a good deal of traffic about perl internals.

2.10) Where can I get training classes on Perl?

USENIX, LISA, SUG, WCSAS, AUUG, FedUnix and Europen sponsor tutorials of varying lengths on Perl at the System Administration and General Conferences. These public classes are typically taught by Tom Christiansen*.

In part, Tom and Randal teach Perl to help keep bread on their tables long enough while they continue their pro bono efforts of documenting perl (Tom keeps writing more man pages for it :-) and expanding the perl toolkit through extension libraries, work which they enjoy doing as it's fun and helps out the whole world, but which really doesn't pay the bills. Such is the nature of free(ly available) software. Send mail to <perlclasses@perl.com> for details and availability.

Tom is also available to teach on-site classes, included courses on advanced perl and perl5. Classes run anywhere from one day to week long sessions and cover a wide range of subject matter. Classes can include lab time with exercises, a generally beneficial aspect. If you would like more information regarding Perl classes or when the next public appearances are, please contact Tom directly at 1.303.444.3212.

Randal Schwartz* provides a 2-day lecture-only and a 4-5 day lecture-lab course based on his popular book ``Learning Perl''. For details, contact Randal directly via email or at 1.503.777.0095.

Internet One provides a 2 day ``Introduction to Perl'' and 2 day ``Advanced Perl'' workshop. The 50% hands-on and 50% lecture format allow attendees to write several programs themselves. Supplied are the user manuals, reference copies of Larry Wall's ``Programming Perl'', and a UNIX directory of all training examples and labs. To obtain outlines, pricing, or scheduling information, use the following:

2.11) What companies use or ship Perl?

At this time, the known list of companies that ship Perl includes at least the following, although some have snuck it into /usr/contrib or its moral equivalent:

BSDI Comdisco Systems CONVEX Computer Corporation Crosspoint Solutions Data General Dell DRD Corporation IBM (SP systems) Intergraph Kubota Pacific Netlabs SGI (without taintperl) Univel

Some companies ship it on their ``User Contributed Software Tape'', such as DEC and HP. Apple Computer has shipped the MPW version of Macintosh Perl on one of their Developer CDs (EssentialsToolsObjects #11) (and they included it under ``Essentials'' :-)

Many other companies use Perl internally for purposes of tools development, systems administration, installation scripts, and test suites. Rumor has it that the large workstation vendors (the TLA set) are seriously looking into shipping Perl with their standard systems ``soon''.

People with support contracts with their vendors are actively encouraged to submit enhancement requests that Perl be shipped as part of their standard system. It would, at the very least, reduce the FTP load on the Internet. :-)

If you know of any others, please send them in.

2.12) Is there commercial, third-party support for Perl?

Not really. Although perl is included in the GNU distribution, at last check, Cygnus does not offer support for it. However, it's unclear whether they've ever been offered sufficient financial incentive to do so. Feel free to try.

On the other hand, you do have comp.lang.perl.misc as a totally gratis support mechanism. As long as you ask ``interesting'' questions, you'll probably get plenty of help. :-)

While some vendors do ship Perl with their platforms, that doesn't mean they support it on arbitrary other platforms. And in fact, all they'll probably do is forward any bug reports on to Larry. In practice, this is far better support than you could hope for from nearly any vendor.

If you purchase a product from Netlabs (the company Larry works for), you actually can get a support contract that includes Perl.

The companies who won't use something unless they can pay money for it will be left out. Often they're motivated by wanting someone whom they could sue. If all they want is someone to help them out with Perl problems, there's always the net. And if they really want to pay someone for that help, well, any of a number of the regular Perl ``dignitaries'' would appreciate the money. ;-)

If companies want ``commercial support'' for it badly enough, speak up -- something might be able to be arranged.

2.13) What is a JAPH? What does "Will hack perl for ..." mean?

These are the ``just another perl hacker'' signatures that some people sign their postings with. About 100 of the of the earlier ones are available from the various FTP sites.

When people started running out of tricky and interesting JAPHs, some of them turned to writing ``Will hack perl for ...'' quotes. While sometimes humourous, they just didn't have the flair of the JAPHs and have since almost completely vanished.

2.14) Where can I get a list of Larry Wall witticisms?

Over a hundred quips by Larry, from postings of his or source code, can be found in many of the FTP sites or through the World Wide Web at "ftp://ftp.cis.ufl.edu/pub/perl/misc/lwall-quotes"

2.15) What are the known bugs?

This is NOT a complete list, just some of the more common bugs that tend to bite people. There are in 5.001:

2.16) Where should I post bugs?

Before posting about a bug, please make sure that you are using the most recent versions of perl (currently 4.036 and 5.001) available. Please also check at the major archive sites to see if there are any development patches available (usually named something like perl5.001a.patch or patch5.001a - the patch itself, or perl5.001a.tar.gz - a prepatched distribution). If you are not using one of these versions, chances are you will be told to upgrade because the bug has already been fixed.

If you are reporting a bug in perl5, the best place to send your bug is <perlbug@perl.com>, which is currently just an alias for <perl5-porters@nicoh.com>. In the past, there have been problems with the perlbug address. If you have problems with it, please send your bug directly to <perl5-porters@nicoh.com>. You may subscribe to the list in the customary fashion via mail to <perl5-porters-request@nicoh.com>. Feel free to post your bugs to the comp.lang.perl.misc newsgroup as well, but do make sure they still go to the mailing list.

If you are posting a bug with a non-Unix port, a non-standard Module (such as Tk, Sx, etc) please see the documentation that came with it to determine the correct place to post bugs.

To enhance your chances of getting any bug you report fixed:

  1. Make sure you are using a production version of perl. Alpha and Beta version problems have probably already been reported and fixed.

  2. Try to narrow the problem down to as small a piece of code as possible. If you can get it down to 1 line of Perl then so much the better.

  3. Include a copy of the output from the myconfig script from the Perl source distribution in your posting.

2.17) Where should I post source code?

You should post source code to whichever group is most appropriate, but feel free to cross-post to comp.lang.perl.misc. If you want to cross-post to alt.sources, please make sure it follows their posting standards, including setting the Followups-To header line to NOT include alt.sources; see their FAQ for details.

2.18) Where can I learn about object-oriented Perl programming?

The perlobj(1) man page is a good place to start, and then you can check out the excellent perlbot(1) man page written by the dean of perl o-o himself, Dean Roehrich. Areas covered include the following:

Idx  Subsections in perlobj.1          Lines
 1   NAME                                  2
 2   DESCRIPTION                          16
 3   An Object is Simply a Reference      60
 4   A Class is Simply a Package          31
 5   A Method is Simply a Subroutine      34
 6   Method Invocation                    75
 7   Destructors                          14
 8   Summary                               7

Idx  Subsections in perlbot.1          Lines
 1   NAME                                  2
 2   INTRODUCTION                          9
 3   Instance Variables                   43
 4   Scalar Instance Variables            21
 5   Instance Variable Inheritance        35
 6   Object Relationships                 33
 7   Overriding Superclass Methods        49
 8   Using Relationship with Sdbm         45
 9   Thinking of Code Reuse              111

 

The section on instance variables should prove very helpful to those wondering how to get data inheritance in perl.

2.19) Where can I learn about linking C with Perl? [h2xs, xsubpp]

While it used to be deep magic, how to do this is now revealed in the perlapi(1) , perlguts(1) , and perlcall(1) man pages, which treat with this matter extensively. You should also check the many extensions that people have written (see question 1.19), many of which do this very thing.

2.20) What is perl.com?

Perl.com is just Tom's domain name, registered as dedicated to ``Perl training and consulting''. While not a full ftp site (he hasn't got the bandwidth (yet)), it does have some interesting bits, most of which are replicated elsewhere. It serves as a clearinghouse for certain perl related mailing lists. The following aliases work:

perl-packrats:          The archivist list
perl-porters:           The porters list
perlbook:               The Camel/Llama/Alpaca writing committee
perlbugs:               The bug list (perl-porters for now)
perlclasses:            Info on Perl training
perlfaq:                Submissions/Errata to the Perl FAQ
			(Tom and Steve)
perlrefguide:           Submissions/Errata to the Perl RefGuide
			(Johan) 

2.21) What do the asterisks (*) throughout the FAQ stand for?

To keep from cluttering up the FAQ and for easy reference all email addresses have been collected in this location. For each person listed, I offer my thanks for their input and help.

Larry Wall            lwall@netlabs.com
Tom Christiansen      tchrist@wraeththu.cs.colorado.edu
Stephen P Potter      spp@psa.pencom.com
Andreas König         k@franz.ww.TU-Berlin.DE
Bill Eldridge         bill@cognet.ucla.edu
Buzz Moschetti        buzz@bear.com
Casper H.S. Dik       casper@fwi.uva.nl
David Muir Sharnoff   muir@tfs.com
Dean Roehrich         roehrich@ironwood.cray.com
Dominic Giampaolo     dbg@sgi.com
Frédéric Chauveau     fmc@pasteur.fr
Gene Spafford         spaf@cs.purdue.edu
Guido van Rossum      guido@cwi.nl
Henk P Penning        henkp@cs.ruu.nl
Jeff Friedl           jfriedl@omron.co.jp
Johan Vromans         jv@NL.net
John Dallman          jgd@cix.compulink.co.uk
John Lees             lees@pixel.cps.msu.edu
John Ousterhout       ouster@eng.sun.com
Jon Biggar            jon@netlabs.com
Ken Lunde             lunde@mv.us.adobe.com
Malcolm Beattie       mbeattie@sable.ox.ac.uk
Matthias Neeracher    neeri@iis.ee.ethz.ch
Michael D'Errico      mike@software.com
Nick Ing-Simmons      Nick.Ing-Simmons@tiuk.ti.com
Randal Schwartz       merlyn@stonehenge.com
Roberto Salama        rs@fi.gs.com
Steven L Kunz         skunz@iastate.edu
Theodore C. Law       TEDLAW@TOROLAB6.VNET.IBM.COM
Thomas R. Kimpton     tom@dtint.dtint.com
Tim Bunce             timbo@ig.co.uk
Timothy Murphy        tim@maths.tcd.ie
UF Computer Staff     consult@cis.ufl.edu
William Setzer        William_Setzer@ncsu.edu



Programming Aids


3.1) How do I use perl interactively?
3.2) Is there a perl profiler?
3.3) Is there a yacc for perl?
3.4) Is there a pretty printer (similar to indent(1)) for perl?
3.5) How can I convert my perl scripts directly to C or compile them into binary form?
3.6) Where can I get a perl mode for emacs?
3.7) Is there a perl shell?
3.8) How can I use curses with perl?
3.9) How can I use X or Tk with perl?
3.10) Can I dynamically load C user routines?
3.11) What is undump and where can I get it?
3.12) How can I get '#!perl' to work under MS-DOS?
3.13) Can I write useful perl programs on the command line?
3.14) What's a "closure"?

3.1) How can I use Perl interactively?

The easiest way to do this is to run Perl under its debugger. If you have no program to debug, you can invoke the debugger on an `empty' program like this:

perl -de 0

(The more positive hackers prefer perl -de 1. :-)

Now you can type in any legal Perl code, and it will be immediately evaluated. You can also examine the symbol table, get stack backtraces, check variable values, and if you want to, set breakpoints and do the other things you can do in a symbolic debugger.

3.2) Is there a Perl profiler?

While there isn't one included with the perl source distribution (yet) various folks have written packages that allow you to do at least some sort of profiling. The strategy usually includes modifying the perl debugger to handle profiling. Authors of these packages include

Wayne Thompson me@anywhere.EBay.Sun.COM Ray Lischner lisch@sysserver1.mentor.com Kresten Krab Thorup krab@iesd.auc.dk

The original articles by these folks containing their profilers are available at ftp://convex.com/pub/perl/info/profiling.shar.

Recently, Dean Roehrich* has written a profiler for version 5 that likely will be distributed with the standard release. For now, it should be available through any of the extension archives as DProf.tar.gz.

3.3) Is there a yacc for Perl?

Yes!! It's a version of Berkeley yacc that outputs Perl code instead of C code! You can get this from ftp://ftp.sterling.com/local/perl-byacc1.8.2.tar.Z, or send the author mail for details.

3.4) Is there a pretty-printer (similar to indent(1)) for Perl?

That depends on what you mean. If you want something that works like vgrind on Perl programs, then the answer is ``yes, nearly''. Here's a vgrind entry for perl:


PERL|perl|Perl:\
    :pb=^\d?(sub|package)\d\p\d:\
    :bb={:be=}:cb=#:ce=$:sb=":se=\e":lb=':\
    :le=\e':tl:\
    :id=_:\
    :kw=\
    if for foreach unless until while continue else elsif \
    do eval require \
    die exit \
    defined delete reset \
    goto last redo next dump \
    local undef return  \
    write format  \
    sub package

It doesn't actually do everything right; in particular, things like $#, $', s#/foo##, and $foo'bar all confuse it.

David Levine uses this:

# perl 4.x                    David Levine <levine@ics.uci.edu> 05 apr 1993
# Derived from Tom Christiansen's perl vgrindef.  I'd like to treat all  of
# perl's built-ins as  keywords,  but vgrind   fields are  limited  to 1024
# characters  and the built-ins overflow that (surprise  :-).  So, I didn't
# include the dbm*, end*, get*, msg*, sem*, set*,  and  shm* functions.   I
# couldn't come up with an easy way to  distinguish beginnings  of literals
# ('...') from package prefixes, so literals are not marked.
# Be sure to:
# 1) include whitespace between a subprogram name and its opening {
# 2) include whitespace before a comment (so that $# doesn't get
# interpreted as one).
perl4:\
	:pb=^\d?(sub|package)\d\p\d:\
	:id=$%@_:\
	:bb=\e{:be=\e}:cb=\d\e#:ce=$:sb=\e":se=\e":\
	:kw=accept alarm atan2 bind binmode caller chdir chmod chop \
chown chroot close closedir connect continue cos crypt defined delete \
die do dump each else elsif eof eval exec exit exp fcntl fileno flock \
for foreach fork format getc gmtime goto grep hex if include index int \
ioctl join keys kill last length link listen local localtime log lstat \
m mkdir next oct open opendir ord pack package pipe pop print printf \
push q qq qx rand read readdir readlink recv redo rename require reset \
return reverse rewinddir rindex rmdir s scalar seek seekdir select send \
shift shutdown sin sleep socket socketpair sort splice split sprintf \
sqrt srand stat study sub substr symlink syscall sysread system \
syswrite tell telldir time times tr truncate umask undef unless unlink \
unpack unshift until utime values vec wait waitpid wantarray warn while \
write y: 

If what you mean is whether there is a program that will reformat the program much as indent(1) will do for C, then the answer is no. The complex feedback between the scanner and the parser (as in the things that confuse vgrind) make it challenging at best to write a stand-alone Perl parser.

Of course, if you follow the guidelines in perlstyle(1), you shouldn't need to reformat.

3.5) How can I convert my perl scripts directly to C or compile them into binary form?

The short answer is: ``No, you can't compile perl into C. Period.''

However, having said that, it is believed that it would be possible to write a perl to C translator, although it is a PhD thesis waiting to happen. Anyone need a good challenging thesis?

In the way of further, detailed explication, it seems that the reasons people want to do this usaully break down into one or more of the following:

  1. speed
  2. secrecy
  3. maintainability

  1. SPEED:

    1. You can't turn perl source code or perl intermediary code into native machine code to make it run faster, and saving the perl intermediary code doesn't really buy you as much as you'd like. If you really must, check out the undump and unexec alternatives. If your motivations are speed, then this may or may not help you much.

      You might also look into autoloading functions on the fly, which can greatly reduce start-up time.

    2. If you have a few routines that are bogging you down, you just possibly might wish to hand-translate just them into C, then dynamically load these in. See perlapi(1) for details. Most of the time, however, reorganizing your perl algorithm is the best way to address this.

  2. SOURCE-CODE SECRECY:

    1. If you're trying to stop people from seeing what you're doing, you can shroud it, i.e. turn all the idents into silly stuff, rearrange strings, and remove redundant white space. There's a program out there called ShroudIt! that works on a number of languages, including Perl. Note that it is a commercial product though. Contact David Webber (webber@lnk.com) for more information.
    2. You might also look into the cryptswitch() stuff in the perl source, which would allow you to ship something in a form they can't read. This isn't particulary well-documented.

    3. If you're worried about them using your software without licence, you put some huge disclaimer at the top that says something like the following. This is actually the best solution, because only a legal solution will really work if legality is what you're worried about: trying to solve legal problems with technical solutions is not worth the effort, and too easily circumvented.
      This is UNPUBLISHED PROPRIETARY SOURCE CODE of XYZZY, Inc.; the contents of this file may not be disclosed to third parties, copied or duplicated in any form, in whole or in part, without the prior written permission of XYZZY, Inc.

      Permission is hereby granted soley to the licencee for use of this source code in its unaltered state. This source code may not be modified by licencee except under direction of XYZZY Inc. Neither may this source code be given under any circumstances to non-licensees in any form, including source or binary. Modification of this source constitutes breach of contract, which voids any potential pending support responsibilities by XYZZY Inc. Divulging the exact or paraphrased contents of this source code to unlicensed parties either directly or indirectly constitutes violation of federal and international copyright and trade secret laws, and will be duly prosecuted to the fullest extent permitted under law.

      This software is provided by XYZZY Inc. ``as is'' and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the regents or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

  3. MAINTAINABILITY:

    1. If you just want to stop people from changing it because you're concerned about support issues, you can put in a big disclaimer at the top that says that if they touch the file they void the warranty, and then make them give you a size, checksum, and version of the file before answering any questions about it.

      If you maintain a central site that distributes software to internal client machines, use rdist(1) to send around a proper version periodically, perhaps using the -y option on the install to flag destinations younger than the source.

      Let it be noted than in the many, many years that Perl's author has been releasing and supporting freely redistributable software, he has NEVER ONCE been bitten by a bogus bug report generated by someone breaking his code because they had access to it. Rather, he and many other open software provided (where open software means that for which the source is provided, the only truly open software) have saved themselves countless hours of labor thousands of times over because they've allowed people to inspect the source for themselves. Proprietary source-code hoarding is its own headache.

      Thus, obscurity for the sake of maintainability would seem to be a red herring.

    2. If you can't count on perl being installed at the destination customer, then by all means, merely ship it with your program. This is no hardship, since software providers are accustomed to shipping software in machine-specific binary form. The basic idea is as simple as:
      
      shar /usr/local/{lib,bin,man}/perl myprog
      
      
      Just don't overwrite their own Perl installation if they have one!

3.6) Where can I get a perl-mode for emacs?

Since Emacs version 19 patchlevel 22 or so, there has been both a perl-mode.el and support for the perl debugger built in. These should come with the standard Emacs 19 distribution.

In the perl source directory, you'll find a directory called ``emacs'', which contains several files that should help you.

Note that the perl-mode of emacs will have fits with main'foo (single quote), and mess up the indentation and hilighting. However, note that in perl5, you should be using main::foo. By the way, did we mention that you should upgrade?

3.7) Is there a Perl shell?

Not really. Perl is a programming language, not a command interpreter. There is a very simple one called ``perlsh'' included in the Perl source distribution. It just does this:
    $/ = '';        # set paragraph mode
    $SHlinesep = "\n";
    while ($SHcmd = <>) {
	$/ = $SHlinesep;
	eval $SHcmd; print $@ || "\n";
	$SHlinesep = $/; $/ = '';
    }
Not very interesting, eh?

Daniel Smith <dls@best.com> is working on an interactive Perl shell called SoftList. It's currently at version 3.0b7a (beta). SoftList 3.0b7a has tcsh-like command line editing, can let you define a file of aliases so that you can run chunks of perl or UNIX commands, and so on. You can pick up a copy at ftp.best.com in /pub/dls/SoftList-3.0b7a.gz.

3.8) How can I use curses with perl?

In release 4 of perl, the only way to do this was was to build a curseperl binary by linking in your C curses library as described in the usub subdirectory of the perl sources. This requires a modicum of work, but it will be reasonably fast since it's all in C (assuming you consider curses reasonably fast. :-) Programs written using this method require the modified curseperl, not vanilla perl, to run. While this is something of a disadvantage, experience indicates that it's better to use curseperl than to try to roll your own using termcap directly.

Fortunately, in version 5, Curses is a dynamically loaded extension by William Setzer*. You should be able to pick it up wherever you get Perl 5 from, or at least these places (expect that the version may change by the time you read this):

For a good example of using curses with Perl, you might want to pick up a copy of Steven L Kunz's* ``perl menus'' package (``menu.pl'') via anonymous FTP from ``ftp.iastate.edu''. It's in the directory /pub/perl as:

menu.pl.v3.1.tar.Z
menu.pl is a complete menu front-end for perl+curses and demonstrates a lot of things (plus it is useful to boot if you want full-screen menu selection ability). It provides full-screen menu selection ability for three menu styles (single-selection, multiple-selection, and ``radio-button''). The ``perl menus'' package also includes routines for full-screen data entry. A ``template'' concept is implemented to create a simple (yet flexible) perl interface for building data-entry screens for registration, database, or other record-oriented tasks.

menu.pl is supported on Perl4/curseperl and Perl5/Curses. Complete user documentation is provided along with several demos and ``beginner applications''. A menu utility module is provided that is a collection of useful Perl curses routines (such as "pop-up query boxes) that may be called from your applications.

Another possibility is to use Henk Penning's cterm package, a curses emulation library written in perl. cterm is actually a separate program with which you communicate via a pipe. It is available from ftp.cs.ruu.nl [131.211.80.17] via anonymous ftp. in the directory pub/PERL. You may also acquire the package via email in compressed, uuencoded form by sending a message to mail-server@cs.ruu.nl containing these lines:


    begin
    send PERL/cterm.shar.Z
    end

See the question on retrieving perl via mail for more information on how to retrieve other items of interest from the mail server there.

3.9) How can I use X or Tk with Perl?

Right now, you have several choices. If you are still using perl4, use the WAFE or STDWIN packages, or try to make your own usub binding.

However, if you've upgraded to version 5, you have several exciting possibilities, with more popping up each day. Right now, Tk and Sx are the best known such extensions.

If you like the tk package, you should get the Tk extension kit, written by Nick Ing-Simmons*. The official distribution point is at

ftp://ftp.wpi.edu/perl5/private/Tk-b8.tar.gz

but many of the major archive sites now have it in their /ext{entions} directory also. Depending upon your location, you may be better off checking there. Also, understand that the version number may have changed by the time you read this.

This package replaced the tkperl5 project, by Malcolm Beattie*, which was based on an older version of Tk, 3.6 as compared to the current 4.X. This package was also known as nTk (new Tk) while it was in the alpha stages, but has been changed to just Tk now that it is in beta. Also, be advised that you need at least perl5.001 (preferably 5.002, when it becomes available) and the official unofficial patches.

You may also use the old Sx package, (Athena & Xlib), written by originally written by by Dominic Giampaolo*, then and rewritten for Sx by Frédéric Chauveau*. It's available from these sites:

STDWIN is a library written by Guido van Rossum* (author of the Python programming language) that is portable between Mac, Dos and X11. One could write a Perl agent to speak to this STDWIN server.

WAFE is a package that implements a symbolic interface to the Athena widgets (X11R5). A typical Wafe application consists in our framework of two parts: the front-end (we call it Wafe for Widget[Athena]front end) and an application program running typically as a separate process. The application program can be implemented in an arbitrary programming language and talks to the front-end via stdio. Since Wafe (the front-end) was developed using the extensible TCL shell (cite John Ousterhout), an application program can dynamically submit requests to the front-end to build up the graphical user interface; the application can even down-load application specific procedures into the front-end. The distribution contains sample application programs in Perl, GAWK, Prolog, TCL, and C talking to the same Wafe binary. Many of the demo applications are implemented in Perl. Wafe 0.9 can be obtained via anonymous ftp from
ftp.wu-wien.ac.at[137.208.3.5]:pub/src/X11/wafe-0.9.tar.Z

Alternatively, you could use wish from tcl.

#!/usr/local/bin/perl
#####################################################################
#  An example of calling wish as a subshell under Perl and
#  interactively communicating with it through sockets.
#
#  The script is directly based on Gustaf Neumann's perlwafe script.
#
#  Dov Grobgeld dov@menora.weizmann.ac.il
#  1993-05-17
#####################################################################

    $wishbin = "/usr/local/bin/wish";

    die "socketpair unsuccessful: $!!\n" unless socketpair(W0,WISH,1,1,0);
    if ($pid=fork) {
	    select(WISH); $| = 1;
	    select(STDOUT);


	# Create some TCL procedures
	    print WISH 'proc echo {s} {puts stdout $s; flush stdout}',"\n";

	# Create the widgets
	print WISH &;lt;&;lt;TCL;
	# This is a comment "inside" wish

	frame .f -relief raised -border 1 -bg green
	pack append . .f {top fill expand}

	button .f.button-pressme -text "Press me" -command {
	    echo "That's nice."
	}
	button .f.button-quit -text quit -command {
	    echo "quit"
	}
	pack append .f .f.button-pressme {top fill expand} \\
		       .f.button-quit {top expand}

TCL
	;
	# Here is the main loop which receives and sends commands
	# to wish.
	while () {
	    chop;
	    print "Wish sais: <$_>\n";
	    if (/^quit/) { print WISH "destroy .\n"; last; }
	}
	    wait;
    } elsif (defined $pid) {
	open(STDOUT, ">&W0");
	open(STDIN, ">&W0");
	close(W0);
	select(STDOUT); $| = 1;
	exec "$wishbin --";
    } else {
	die "fork error: $!\n";
    }

3.10) Can I dynamically load C user routines?

Yes -- dynamic loading comes with the distribution. That means that you no longer need 18 different versions of fooperl floating around. In fact, all of perl can be stuck into a libperl.so library and then your /usr/local/bin/perl binary reduced to just 50k or so. See DynaLoader(3pm) for details.

In perl4, the answer was kinda. One package has been released that does this, by Roberto Salama*. He writes:

Here is a version of dylperl, dynamic linker for perl. The code here is based on Oliver Sharp's May 1993 article in Dr. Dobbs Journal (Dynamic Linking under Berkeley UNIX).

  dyl.h 
  dyl.c - code extracted from Oliver Sharp's article

  hash.h
  hash.c - Berkeley's hash functions, should use perl's but
	   could not be bothered

dylperl.c - perl usersubs
  user.c - userinit function

sample.c - sample code to be dyl'ed
sample2.c -          "
 test.pl - sample perl script that dyl's sample*.o

The Makefile assumes that uperl.o is in /usr/local/src/perl/... You will probably have to change this to reflect your installation. Other than that, just type 'make'...

The idea behind being able to dynamically link code into perl is that the linked code should become perl functions, i.e. they can be invoked as &foo(...). For this to happen, the incrementally loaded code must use the perl stack, look at sample.c to get a better idea.

The few functions that make up this package are outlined below.


&dyl("file.o"): dynamically link file.o. All functions 
   and non-static variables become visible from within perl. This
   function returns a pointer to an internal hash table corresponding
   to the symbol table of the newly loaded code.

eg: $ht = &dyl("sample.o")


This function can also be called with the -L and -l ld options.


   eg: $ht = &dyl("sample2.o", "-L/usr/lib", "-lm")
       will also pick up the math library if sample.o
       accesses any symbols there.


&dyl_find("func"): find symbol 'func' and return its symbol table entry


&dyl_functions($ht): print the contents of the internal hash table
&dyl_print_symbols($f): prints the contents of the symbol returned by
dyl_find() 

There is very little documentation, maybe something to do for a future release. The files sample.o, and sample2.o contain code to be incrementally loaded, test.pl is the test perl script.

Comments are welcome. I submit this code for public consumption and, basically, am not responsible for it in any way.

3.11) What is undump and where can I get it?

The undump program comes from the TeX distribution. If you have TeX, then you may have a working undump. If you don't, and you can't get one, AND you have a GNU emacs working on your machine that can clone itself, then you might try taking its unexec() function and compiling Perl with -DUNEXEC, which will make Perl call unexec() instead of abort(). You'll have to add unexec.o to the objects line in the Makefile. If you succeed, post to comp.lang.perl.misc about your experience so others can benefit from it.

If you have a version of undump that works with Perl, please submit its anon-FTP whereabouts to the FAQ maintainer.

3.12) How can I get #!perl to work under MS-DOS?

John Dallman* has written a program ``#!perl.exe" which will do this. It is available through anonymous ftp from ftp.ee.umanitoba.ca in the directory /pub/msdos/perl/hbp_30.zip. This program works by finding the script and perl.exe, building a command line and running perl.exe as a child process. For more information on this, contact John directly.

3.13) Can I write useful perl programs on the command line?

Sure, if they're simple enough. Of course, for most programs, you'll enter them in a file and call perl on them from your shell. That way you can go into the hack/execute/debug cycle. But there are plenty of useful one-liner: see below. (Things marked perl5 need to be run from v5.000 or better, but the rest don't care.)

# what's octal value of random char (":" in this case)?
perl -e 'printf "%#o\n", ord(shift)' ":"

# sum first and last fields
perl -lane 'print $F[0] + $F[1]'

# strip high bits
perl -pe 'tr/\200-\377/\000-\177/'

# find text files
perl -le 'for(@ARGV) {print if -f && -T}' *

# trim newsrc
perl5 -i.old -pe 's/!.*?(\d+)$/! 1-$1/' ~/.newsrc

# cat a dbmfile
perl -e 'dbmopen(%f,shift,undef);while(($k,$v)=each%f){print "$k:\
	$v\n"}' /etc/aliases 

# remove comments from C program
perl5 -0777 -pe 's{/\*.*?\*/}{}gs' foo.c

# make file a month younger than today, defeating reaper daemons
perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *

# find first unused uid
perl5 -le '$i++ while getpwuid($i); print $i'

# find first unused uid after 100, even with perl4
perl -le '$i = 100; $i++ while ($x) = getpwuid($i); print $i'

# detect pathetically insecurable systems
perl5 -le 'use POSIX; print "INSECURE" unless sysconf(_PC_CHOWN_RESTRICTED)'

# display reasonable manpath
echo $PATH | perl5 -nl -072 -e '
    s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}'

Ok, the last one was actually an obfuscate perl entry. :-)

3.14) What's a "closure"?

(Larry wrote) This is a notion out of the Lisp world that says if you define an anonymous function in a particular lexical context, it pretends to run in that context even when it's called outside of the context.

In human terms, it's a funny way of passing arguments to a subroutine when you define it as well as when you call it. It's useful for setting up little bits of code to run later, such as callbacks. You can even do object-oriented stuff with it, though Perl provides a different mechanism to do that already.

You can also think of it as a way to write a subroutine template without using eval.

Here's a small example of how this works:


    sub newprint {
	my $x = shift;
	return sub { my $y = shift; print "$x, $y!\n"; };
    }
    $h = newprint("Howdy");
    $g = newprint("Greetings");

    # Time passes...

    &$h("world");
    
    &$g("earthlings");

This prints:


    Howdy, world!
    Greetings, earthlings!

Note particularly that $x continues to refer to the value passed into newprint() despite the fact that the my $x has seemingly gone out of scope by the time the anonymous subroutine runs. That's what closure is all about.

This only applies to lexical variables, by the way. Dynamic variables continue to work as they have always worked. Closure is not something that most Perl programmers need trouble themselves about to begin with.


General Programming, Regexps, and I/O


4.1) What are all these $@%*<> signs and how do I know when to use them?
4.2) Why do Perl operators have different precedence than C operators?
4.3) What's the difference between dynamic and static (lexical) scoping?
4.4) What's the difference between deep and shallow binding?
4.5) How can I manipulate fixed-record-length files?
4.6) How can I make a file handle local to a subroutine?
4.7) How can I sleep or alarm for under a second?
4.8) How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
4.9) How can I catch signals?
4.10) Why isn't my octal data interpretted correctly?
4.11) How can I compare two date strings?
4.12) How can I find the Julian Day?
4.13) Does perl have a round function? What about ceil() and floor()?
4.14) What's the fastest way to code up a given task in perl?
4.15) Do I always/never have to quote my strings or use semicolons?
4.16) What is variable suicide and how can I prevent it?
4.17) What does ``Malformed command links'' mean?
4.18) How can I set up a footer format to be used with write()?
4.19) Why does my program keep growing in size?
4.20) Can I do RPC?
4.21) Why doesn't my sockets program work under System V (Solaris)? What does the error message ``Protocol not supported'' mean?
4.22) How can I quote a variable to use in a regexp?
4.23) How can I change the first N letters of a string?
4.24) How can I count the number of occurrences of a substring within a string?
4.25) Can I use Perl regular expressions to match balanced text?
4.26) What does it mean that regexps are greedy? How can I get around it?
4.27) How do I use a regular expression to strip C style comments from a file?</