Archive-name: perl-faq Version: $Id: perl-intro,v 2.8 1995/05/15 15:43:59 spp Exp spp $ Posting-Frequency: bi-weekly Last Edited: Thu Jan 11 00:52:58 1996 by spp (Stephen P Potter) on syrinx.psa.com Hear ye, hear ye. This most honourable session on Perl Frequently Asked Questions is hereby called to order. Please stand and show your respect for those that have gone before us. Let us honour Larry Wall*, the father of Perl who unselfishly spends vast amounts of time reviewing this document for veracity and accuracy. Let us also honour Tom Christiansen* without whom this document would not exist. Finally, let us collectively honour the members of comp.lang.perl.misc who have offered much advice and corrections to this list. 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 reservered. 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 . Part 1 - 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? Part 2 - 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? Part 3 - 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"? Part 4 - General Programming, Regular Expressions (Regexp) 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? 4.28) How can I split a [character] delimited string except when inside [character]? 4.29) Why doesn't "local($foo) = ;" work right? 4.30) How can I detect keyboard input without reading it? 4.31) How can I read a single character from the keyboard under UNIX and DOS? 4.32) How can I get input from the keyboard without it echoing to the screen? 4.33) Is there any easy way to strip blank space from the beginning/end of a string? 4.34) How can I output my numbers with commas added? 4.35) How do I expand tags in a string? 4.36) What's wrong with grep in a void context? Part 5 - Arrays and Shell and External Program Interactions 5.1) What is the difference between $array[1] and @array[1]? 5.2) How can I make an array of arrays or other recursive data types? 5.3) How can I make an array of structures containing various data types? 5.4) How can I extract just the unique elements of an array? 5.5) How can I tell whether an array contains a certain element? 5.6) How can I sort an associative array by value instead of by key? 5.7) How can I know how many entries are in an associative array? 5.8) What's the difference between "delete" and "undef" with %arrays? 5.9) Why don't backticks work as they do in shells? 5.10) Why does my converted awk/sed/sh script run more slowly in perl? 5.11) How can I call my system's unique C functions from perl? 5.12) Where do I get the include files to do ioctl() or syscall()? [h2ph] 5.13) Why do setuid perl scripts complain about kernel problems? 5.14) How can I open a pipe both to and from a command? 5.15) How can I capture STDERR from an external command? 5.16) Why doesn't open() return an error when a pipe open fails? 5.17) Why can't my script read from STDIN after I gave it ^D (EOF)? 5.18) How can I translate tildes (~) in a filename? 5.19) How can I convert my shell script to perl? 5.20) Can I use perl to run a telnet or ftp session? 5.21) Why do I sometimes get an "Argument list to long" when I use <*>? 5.22) How do I do a "tail -f" in perl? 5.23) Is there a way to hide perl's command line from programs such as "ps"? 5.24) I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible? 5.25) How can I pass a filehandle to a function, or make a list of filehandles? 5.26) How can I open a file with a leading ">" or trailing blanks? 5.27) How can I tell if a variable is tainted? This posting contains answers to general information and availability questions. The following questions are answered in this posting: 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 arbi- trary 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, effi- cient, 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 capa- bilities 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. * Enhanced Usability: Perl code can now be written in a much more legible style. Regular expressions have been enhanced to allow minimal matches, conditionals, and much more. Cryptic variable names (although still supported) have been aliased to new nmemonics, using the "English" module, allowing old scripts to run and new scripts to be readable. Error messages and optional warnings are more informative and will catch many common mistakes. See the perldiag(1) man page, which contains pithy prose from Larry Wall* on each and every possible muttering perl might spout at you. * Simplified Grammar: The new yacc grammar is one half the size of the old one. Many of the arbitrary grammar rules have been regularized. The number of reserved words has been cut by 2/3. * Lexical Scoping: Perl variables may now be declared within a lexical scope, similar to C's "auto" variables. This is a great improvement on efficiency and contributes to better privacy. See the my() entry in perlfunc(1). * Arbitrarily nested data structures: Full fledged multidimensional arrays. Any scalar value, including an array element, may now contain a reference to any other variable or subroutine. Easily created anonymous variables and subroutines. See perlref(1). * Modularity and Reusability: The Perl library is now defined in terms of modules which can be easily shared among various packages. Packages can import any or all of a module's published interface. See perlmod(1), perlsub(1), and Exporter(3pm). * Object-oriented programming: A package can function as a class. Dynamic multiple inheritance and virtual methods are supported in a straight-forward manner with little new syntax. Filehandles are now treated as objects. See perlobj(1), perlmod(1), and FileHandle(3pm). * Embeddable and Extensible: Perl can be easily embedded in C/C++ applications, and can either call or be called by your routines through a documented interface. The XS preprocessor is provided to make it easy to glue your C/C++ routines into Perl. Dynamic loading of modules is supported. See perlapi(1), perlcall(1), and DynaLoader(3pm). * POSIX compliant: A major new module is the POSIX module, which provides access to all available POSIX routines and definitions. Seee POSIX(3pm). * Package constructors and destructors: The new BEGIN and END blocks provide means to capture control as a package is being compiled and after the program exits. As a degenerate case, they work just like awk's BEGIN and END when you use the -p or -n switches. See perlmod(1). * Multiple simultaneous DBM implementations: A perl program now has access to DBM, NDBM, SDBM, GDBM and Berkeley DB files in the same script. The dbmopen interface has been generalized to allow any variable to be tied to an object class which defines its access methods. tie/untie now preferable to dbmopen/dbmclose. See the tie() entry in perlfunc(1) and the DB_File(3pm) man pages. * Subroutine definitions may now be autoloaded: The AUTOLOAD mechanism allows any arbitrary semantics to undefined subroutine calls. See the section on Autoloading in the perlsub(1) manpage. * Regular Expression Enhancements: Qualifiers may be followed by a "?" to signify that they should be non-greedy. A "?" directly after an opening paren indicates non backreference grouping and the next character determines the purpose of the match (?:a|b|c) will match any of a b or c without producing a backreference, (?=stuff) does a non-eating look ahead to assure that the next thing is stuff, (?!nonsense) looks ahead to assure that the next thing must not be "nonsense". Embedded whitespace and comments for readability. A consistent extensibility mechanism has been added that is upwardly compatible with all old regexps. Variables may now be interpolated literally into a pattern with \Q or the quotemeta function, which works like \U but backwhacks non-alphanumerics. New m and s "flags" for pattern matching force multi- or single-line matching. The "s" makes "." match "\n". \A and \Z anchor matches to the beginning and end of a string and ignore multiline semantics. \G matches where the previous m//g or s///g left off. * The -w (warnings) switch is much more informative. * References and Objects (see t/op/ref.t) for examples. * => is a synonym for comma and helps group paired arguments, such as initializers for associative arrays and named arguments to subroutines. * All functions, even predeclared subroutines, are treated as list operators or unary operators. Parens are optional. * Flattened interpreter: Compare perl4's eval.c with perl5's pp.c. Compare perl4's 900 line interpreter look with perl5's one line. * eval is now treated like a subroutine call, meaning (among other things) you can return from it. * format value lists may be spread over multiple lines with a do {} block. * flags on the #! line are interpreted even if the script wasn't invoked directly. * ?: is now an lvalue. * list context now propogates to the right side of && and ||, and as the 2nd and 3rd arguments of ?: * preferred package delimiter now :: rather than '. * new "and" and "or" operators, like && and || but with a lower precedence than comma, so they work better with list operators. * New functions abs(), chr(), uc(), ucfirst(), lc(), and lcfirst() * require(number) checks to see that the version is at least that version * qw//, which is equivalent to split(' ', q//) * assignment of a reference to a glob replaces the single element of the glob corresponding to the reference type: *foo = \$bar, * foo = \&bletch; * filehandle methods are supported: output_autoflush STDOUT 1; * Autoload stubs can now call the replacement subroutine with goto &realsub. * Subroutines can be defined lazily in any package by declaring an AUTOLOAD routine, which will be called if a non-existent subroutine is called in that package. * "use" and "no" subsume many features. "use Module LIST" is short for "BEGIN { require Module; import Module LIST }" "no" is identical, except that it calls "unimport" instead. "use integer" and variations of "use strict [vars,refs,subs]" were implemented through new modules. (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. * "@" ***ALWAYS*** interpolates in double quoted strings. Non-array "@"s must be escaped: Mail("foo@bar.com") needs to be Mail("foo\@bar.com"); The compiler catches this. * "open FILE || die" needs to be "open(FILE) || die". The compiler forgives you for this, but won't stop complaining until you fix it. * Barewords are no longer (necessarily) strings: they will actually call the function (if it existed when that code was compiled) instead of returning a string of that value. Check your signal handlers. The 'use strict subs' pragma (see strict(3pm)) will help you with this. * "shift @x + 20" needs to be "shift(@x) + 20" because of precedence, and likewise "$y = scalar keys %foo + 30" needs to be instead "$y = scalar keys(%foo) + 30". * The internal symbol table is called %{PACKAGE::} for any given package. It used to be %{_PACKAGE}. * You may no longer (attempt to) write to read-only variables, like $1, or assign to a substr() past the end of a string. * Various deprecated practices elicit warning messages. * The package delimiter has been changed from ' to ::. Use of ' is deprecated, but still works. Use of :: may break scripts if you aren't careful (especially if you are working with colon delimited data files, like /etc/passwd) 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') ] (Shouldn't that be 42, the Answer to the Great Question of Life, the Universe, and Everything? ;) 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 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. * MS-DOS binaries and source are available at [130.179.8.47] ftp://ftp.ee.umanitoba.ca/pub/msdos/perl/perl4 There are currently half a dozen different ports for MS-DOS. BigPerl4 (v4) is perl4.036 compiled with the Watcom C/C++^32 compiler (32-bit, flat-memory model C compiler) with the following features: * Up to 32MB of memory can be used. * Supports virtual memory. * Works under Windows 3.1 * The perl debugger can be used. * Contains Berkeley DB support. GDBM is no longer supported. Note that the latest version of BigPerl4 can also be found at any SimTel mirror site (ftp.ee.umanitoba.ca does not necessarily have the latest version), such as: ftp://oak.oakland.edu/SimTel/msdos/perl/ A beta-test version of bigperl based on Perl 5.000 can be obtained from the following sites: ftp://ftp.einet.net/pub/perl5 ftp://ftp.khoros.unm.edu/pub/perl/msdos ftp://ftp.ee.umanitoba.ca/pub/msdos/perl/perl5 This beta bigperl also contains ported versions of a2p and s2p. * Windows/NT binaries are available from ftp://ftp.intergraph.com/pub/win32/perl, or at any of the major NT archives. They are compiled for NT 3.5, but appears to work under Win95 also. It is visible to the NT Registry. Dean Troyer* is working on extending the visibility to SAM and the Event Log. His current work-in-progress is available from ftp://pmip.dist.maricopa.edu/pub/nt. * Macintosh binaries and source are available from [130.59.1.40] ftp://nic.switch.ch/software/mac/perl. Version 4.1.3 is perl4.036 compiled with the MPW C compiler * Mac_Perl_413_src.sit.bin Sources * Mac_Perl_413_tool.sit.bin MPW Tool * Mac_Perl_413_appl.sit.bin Standalone Application There is a mailing list for discussing Macintosh Perl. Contact "mpw-perl-request@iis.ee.ethz.ch". Timothy Murphy* also ported a version of perl to the Macintosh using Think C. It has probably been abandoned in favour of the MPW port, but is still available at [134.266.81.10] ftp://ftp.maths.tcd.ie/pub/Mac/perl-4.035/. Matthias Ulrich Neeracher* is working on a perl5 port to the Macintosh. A PowerPC version is available at ftp://err.ethz.ch/pub/neeri/MacPerlBeta. * OS/2 sources are also available at ftp://ftp.cis.ufl.edu/pub/perl/src/4.0/os2. This appears to have been abandoned and added to the official distribution. See the directory os2 in the perl5 sources. * VMS systems should be able to build directly from the standard distribution. * Amiga sources are not available from ftp.cis.ufl.edu, but can be found at any Aminet archive, notably: * ftp://ftp.wustl.edu/pub/aminet/dev/lang/ * ftp://ftp.uni-erlangen.de/pub/aminet/dev/lang/ * ftp://ftp.doc.ic.ac.uk/pub/aminet/dev/lang/ * ftp://ftp.funet.fi/pub/languages/perl/ports/perl4/amiga 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 ftp://ftp.cis.ufl.edu/pub/perl/ext (also linked at ftp://ftp.cis.ufl.edu/pub/perl/src/5.0/ext) ftp://ftp.khoros.unm.edu/pub/perl/extensions/ ftp://ftp.metronet.com/pub/perlinfo/perl5/ ftp://ftp.cs.ruu.nl/pub/PERL/perl5.0/ext ftp://black.ox.ac.uk/src/ALPHA/ 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 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.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 + 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. 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): ISBN 1-56592-042-2 (English) ISBN 4-89502-678-1 (Japanese) ISBN 2-84177-005-2 (French) ISBN 3-930673-08-8 (German) 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 it's 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: [] ftp://ftp.uu.net/languages/perl/perlref-4.036.1.tar.gz [] ftp://ftp.cs.ruu.nl/pub/DOC/perlref-4.036.1.tar.gz [] ftp://ftp.khoros.unm.edu/pub/perl/perlref-4.036.1.tar.gz 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 it's 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 it's existance. 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 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. 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 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 "Program- ming Perl", and a UNIX directory of all training examples and labs. To obtain outlines, pricing, or scheduling information, use the following: o Phone: 1.303.444.1993 o Email: info@InternetOne.COM o See our Ad in the "SysAdmin" magazine o View the outlines via the Web: http://www.InternetOne.COM/ 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 (Essentials*Tools*Objects #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. 5.001: op.c: Inconsistent parameter definition for pad_findlex - fixed in 5.001a, get development patches a-l. walk.c: redeclaration of emit_split - fixed in perl5.001a, get development patches a-l. On linux systems "make test" fails on "op/exec Failed test 5". This is a known bug with bash, not perl. You can get a new version of bash. Also on linux systems, "make test" hangs on lib/anydbm if you include NDBM in the extentions. Do not include NDBM. Another linux problem is getting Dynamic Loading to work. You must use dld-2.3.6 (the newest version at the time of writing) to use Dynamic Loading. - All versions of h2ph previous to the one supplied with perl5.001 tended to generate improper header files. Something such as: #if __GNUC__ was incorrectly translated into if ( &__GNUC__ ) { instead of if ( defined(&__GNUC__) ? &__GNUC__ : 0 ) { Perl5 binaries compiled on SunOS4 exhibit strange behaviour on SunOS5. For example, backticks do not work in the scripts. You need to compile perl for both architectures, even with Binary Compatibility. 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 , which is currently just an alias for . In the past, there have been problems with the perlbug address. If you have problems with it, please send your bug directly to . You may subscribe to the list in the customary fashion via mail to . 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 * Tom Christiansen * Stephen P Potter * Andreas Koenig * Bill Eldridge * Buzz Moschetti * Casper H.S. Dik * David Muir Sharnoff * Dean Roehrich * Dominic Giampaolo , * Frederic Chauveau * Gene Spafford * Guido van Rossum * Henk P Penning * Jeff Friedl * Johan Vromans * John Dallman * John Lees * John Ousterhout * Jon Biggar * Ken Lunde * Malcolm Beattie * Matthias Neeracher * Michael D'Errico * Nick Ing-Simmons * Randal Schwartz * Roberto Salama * Steven L Kunz * Theodore C. Law * Thomas R. Kimpton * Timothy Murphy * UF Computer Staff 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 Ray Lischner Kresten Krab Thorup The original articles by these folks containing their profilers are available at ftp://convex.com/pub/perl/info/profiling.shar. Recently, Dean Roerich* 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 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: A) speed B) secrecy C) maintainability 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. 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. SOURCE-CODE SECRECY: 2) 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. 3) 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. 4) 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. MAINTAINABILITY: 5) 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. 6) 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 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): ftp://ftp.ncsu.edu/pub/math/wsetzer/cursperl5a6.tar.gz ftp://ftp.metronet.com/pub/perlinfo/perl5/cursperl5a6.tar.gz ftp://ftp.cs.ruu.nl/pub/PERL/perl5.0/cursperl5a6.tar.gz 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 Frederic Chauveau*. It's available from these sites: ftp://ftp.pasteur.fr/pub/Perl/Sx.tar.gz ftp://ftp.khoros.unm.edu/pub/perl/extensions/Sx.tar.gz ftp://ftp.metronet.com/pub/perlinfo/perl5/Sx.tar.gz 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 <) { 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 DynLoader(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. 4.1) What are all these $@%*<> signs and how do I know when to use them? Those are type specifiers: $ for scalar values @ for indexed arrays % for hashed arrays (associative arrays) * for all types of that symbol name. These are sometimes used like pointers in perl4, but perl5 uses references. <> are used for inputting a record from a filehandle. \ takes a reference to something. See the question on arrays of arrays for more about Perl pointers. While there are a few places where you don't actually need these type specifiers, except for files, you should always use them. Note that is NOT the type specifier for files; it's the equivalent of awk's getline function, that is, it reads a line from the handle FILE. When doing open, close, and other operations besides the getline function on files, do NOT use the brackets. Beware of saying: $foo = BAR; Which wil be interpreted as $foo = 'BAR'; and not as $foo = ; If you always quote your strings, you'll avoid this trap. Normally, files are manipulated something like this (with appropriate error checking added if it were production code): open (FILE, ">/tmp/foo.$$"); print FILE "string\n"; close FILE; If instead of a filehandle, you use a normal scalar variable with file manipulation functions, this is considered an indirect reference to a filehandle. For example, $foo = "TEST01"; open($foo, "file"); After the open, these two while loops are equivalent: while (<$foo>) {} while () {} as are these two statements: close $foo; close TEST01; but NOT to this: while (<$TEST01>) {} # error ^ ^ note spurious dollar sign This is another common novice mistake; often it's assumed that open($foo, "output.$$"); will fill in the value of $foo, which was previously undefined. This just isn't so -- you must set $foo to be the name of a filehandle before you attempt to open it. Often people request: : How about changing perl syntax to be more like awk or C? I $$mean @less : $-signs = &other *special \%characters? Larry's answer is: Then it would be less like the shell. :-) You'll be pleased to know that I've been trying real hard to get rid of unnecessary punctuation in Perl 5. You'll be displeased to know that I don't think noun markers like $ and @ unnecessary. Not only do they function like case markers do in human language, but they are automatically distinguished within interpolative contexts, and the user doesn't have to worry about different syntactic treatments for variable references within or without such a context. But the & prefix on verbs is now optional, just as "do" is in English. I do hope you do understand what I mean. For example, you used to have to write this: &california || &bust; It can now be written more cleanly like this: california or bust; Strictly speaking, of course, $ and @ aren't case markers, but number markers. English has mandatory number markers, and people get upset when they doesn't agree. It were just convenient in Perl (for the shellish interplative reasons mentioned above) to pull the markers out to the front of each noun phrase. Most people seems to like it that way. It certainly seem to make more sense than putting them on the end, like most varieties of BASIC does. 4.2) How come Perl operators have different precedence than C operators? Actually, they don't; all C operators have the same precedence in Perl as they do in C. The problem is with a class of functions called list operators, e.g. print, chdir, exec, system, and so on. These are somewhat bizarre in that they have different precedence depending on whether you look on the left or right of them. Basically, they gobble up all things on their right. For example, unlink $foo, "bar", @names, "others"; will unlink all those file names. A common mistake is to write: unlink "a_file" || die "snafu"; The problem is that this gets interpreted as unlink("a_file" || die "snafu"); To avoid this problem, you can always make them look like function calls or use an extra level of parentheses: unlink("a_file") || die "snafu"; (unlink "a_file") || die "snafu"; In perl5, there are low precedence "and", "or", and "not" operators, which bind less tightly than comma. This allows you to write: unlink $foo, "bar", @names, "others" or die "snafu"; Sometimes you actually do care about the return value: unless ($io_ok = print("some", "list")) { } Yes, print() returns I/O success. That means $io_ok = print(2+4) * 5; returns 5 times whether printing (2+4) succeeded, and print(2+4) * 5; returns the same 5*io_success value and tosses it. See the perlop(1) man page's section on Precedence for more gory details, and be sure to use the -w flag to catch things like this. One very important thing to be aware of is that if you start thinking of Perl's $, @, %, and & as just flavored versions of C's * operator, you're going to be sorry. They aren't really operators, per se, and even if you do think of them that way. In C, if you write *x[i] then the brackets will bind more tightly than the star, yielding *(x[i]) But in perl, they DO NOT! That's because the ${}, @{}, %{}, and &{} notations (and I suppose the *{} one as well for completeness) aren't actually operators. If they were, you'd be able to write them as *() and that's not feasible. Instead of operators whose precedence is easily understandable, they are instead figments of yacc's grammar. This means that: $$x[$i] is really {$$x}[$i] (by which I actually mean) ${$x}[$i] and not ${$x[$i]} See the difference? If not, check out perlref(1) for gory details. 4.3) What's the difference between dynamic and static (lexical) scoping? What are my() and local()? [NOTE: This question refers to perl5 only. There is no my() in perl4] Scoping refers to visibility of variables. A dynamic variable is created via local() and is just a local value for a global variable, whereas a lexical variable created via my() is more what you're expecting from a C auto. (See also "What's the difference between deep and shallow binding.") In general, we suggest you use lexical variables wherever possible, as they're faster to access and easier to understand. The "use strict vars" pragma will enforce that all variables are either lexical, or full classified by package name. We strongly suggest that you develop your code with "use strict;" and the -w flag. (When using formats, however, you will still have to use dynamic variables.) Here's an example of the difference: #!/usr/local/bin/perl $myvar = 10; $localvar = 10; print "Before the sub call - my: $myvar, local: $localvar\n"; &sub1(); print "After the sub call - my: $myvar, local: $localvar\n"; exit(0); sub sub1 { my $myvar; local $localvar; $myvar = 5; # Only in this block $localvar = 20; # Accessible to children print "Inside first sub call - my: $myvar, local: $localvar\n"; &sub2(); } sub sub2 { print "Inside second sub - my: $myvar, local: $localvar\n"; } Notice that the variables declared with my() are visible only within the scope of the block which names them. They are not visible outside of this block, not even in routines or blocks that it calls. local() variables, on the other hand, are visible to routines that are called from the block where they are declared. Neither is visible after the end (the final closing curly brace) of the block at all. Oh, lexical variables are only available in perl5. Have we mentioned yet that you might consider upgrading? :-) 4.4) What's the difference between deep and shallow binding? 5.000 answer: This only matters when you're making subroutines yourself, at least so far. This will give you shallow binding: { my $x = time; $coderef = sub { $x }; } When you call &$coderef(), it will get whatever dynamic $x happens to be around when invoked. However, you can get the other behaviour this way: { my $x = time; $coderef = eval "sub { \$x }"; } Now you'll access the lexical variable $x which is set to the time the subroutine was created. Note that the difference in these two behaviours can be considered a bug, not a feature, so you should in particular not rely upon shallow binding, as it will likely go away in the future. See perlref(1). 5.001 Answer: Perl will always give deep binding to functions, so you don't need the eval hack anymore. Furthermore, functions and even formats lexically declared nested within another lexical scope have access to that scope. require 5.001; sub mkcounter { my $start = shift; return sub { return ++$start; } } $f1 = mkcounter(10); $f2 = mkcounter(20); print &$f1(), &$f2(); 11 21 print &$f1(), &$f2(), &$f1(); 12 22 13 See the question on "What's a closure?" 4.5) How can I manipulate fixed-record-length files? The most efficient way is using pack and unpack. This is faster than using substr. Here is a sample chunk of code to break up and put back together again some fixed-format input lines, in this case, from ps. # sample input line: # 15158 p5 T 0:00 perl /mnt/tchrist/scripts/now-what $ps_t = 'A6 A4 A7 A5 A*'; open(PS, "ps|"); $_ = ; print; while () { ($pid, $tt, $stat, $time, $command) = unpack($ps_t, $_); for $var ('pid', 'tt', 'stat', 'time', 'command' ) { print "$var: <", eval "\$$var", ">\n"; } print 'line=', pack($ps_t, $pid, $tt, $stat, $time, $command), "\n"; } 4.6) How can I make a file handle local to a subroutine? You must use the type-globbing *VAR notation. Here is some code to cat an include file, calling itself recursively on nested local include files (i.e. those with #include "file", not #include ): sub cat_include { local($name) = @_; local(*FILE); local($_); warn "\n"; if (!open (FILE, $name)) { warn "can't open $name: $!\n"; return; } while () { if (/^#\s*include "([^"]*)"/) { &cat_include($1); } else { print; } } close FILE; } 4.7) How can I call alarm() or usleep() from Perl? If you want finer granularity than 1 second (as usleep() provides) and have itimers and syscall() on your system, you can use the following. You could also use select(). It takes a floating-point number representing how long to delay until you get the SIGALRM, and returns a floating- point number representing how much time was left in the old timer, if any. Note that the C function uses integers, but this one doesn't mind fractional numbers. # alarm; send me a SIGALRM in this many seconds (fractions ok) # tom christiansen sub alarm { require 'syscall.ph'; require 'sys/time.ph'; local($ticks) = @_; local($in_timer,$out_timer); local($isecs, $iusecs, $secs, $usecs); local($itimer_t) = 'L4'; # should be &itimer'typedef() $secs = int($ticks); $usecs = ($ticks - $secs) * 1e6; $out_timer = pack($itimer_t,0,0,0,0); $in_timer = pack($itimer_t,0,0,$secs,$usecs); syscall(&SYS_setitimer, &ITIMER_REAL, $in_timer, $out_timer) && die "alarm: setitimer syscall failed: $!"; ($isecs, $iusecs, $secs, $usecs) = unpack($itimer_t,$out_timer); return $secs + ($usecs/1e6); } 4.8) How can I do an atexit() or setjmp()/longjmp() in Perl? (Exception handling) Perl's exception-handling mechanism is its eval operator. You can use eval as setjmp and die as longjmp. Here's an example of Larry's for timed-out input, which in C is often implemented using setjmp and longjmp: $SIG{ALRM} = TIMEOUT; sub TIMEOUT { die "restart input\n" } do { eval { &realcode } } while $@ =~ /^restart input/; sub realcode { alarm 15; $ans = ; alarm 0; } Here's an example of Tom's for doing atexit() handling: sub atexit { push(@_exit_subs, @_) } sub _cleanup { unlink $tmp } &atexit('_cleanup'); eval <<'End_Of_Eval'; $here = __LINE__; # as much code here as you want End_Of_Eval $oops = $@; # save error message # now call his stuff for (@_exit_subs) { &$_() } $oops && ($oops =~ s/\(eval\) line (\d+)/$0 . " line " . ($1+$here)/e, die $oops); You can register your own routines via the &atexit function now. You might also want to use the &realcode method of Larry's rather than embedding all your code in the here-is document. Make sure to leave via die rather than exit, or write your own &exit routine and call that instead. In general, it's better for nested routines to exit via die rather than exit for just this reason. In Perl5, it is easy to set this up because of the automatic processing of per-package END functions. These work much like they would in awk. See perlfunc(1), perlmod(1) and perlrun(1). Eval is also quite useful for testing for system dependent features, like symlinks, or using a user-input regexp that might otherwise blowup on you. 4.9) How do I catch signals in perl? Perl allows you to trap signals using the %SIG associative array. Using the signals you want to trap as the key, you can assign a subroutine to that signal. The %SIG array will only contain those values which the programmer defines. Therefore, you do not have to assign all signals. For example, to exit cleanly from a ^C: $SIG{'INT'} = 'CLEANUP'; sub CLEANUP { print "\n\nCaught Interrupt (^C), Aborting\n"; exit(1); } There are two special "routines" for signals called DEFAULT and IGNORE. DEFAULT erases the current assignment, restoring the default value of the signal. IGNORE causes the signal to be ignored. In general, you don't need to remember these as you can emulate their functionality with standard programming features. DEFAULT can be emulated by deleting the signal from the array and IGNORE can be emulated by any undeclared subroutine. In 5.001, the $SIG{__WARN__} and $SIG{__DIE__} handlers may be used to intercept die() and warn(). For example, here's how you could promote unitialized variables to trigger a fatal rather merely complaining: #!/usr/bin/perl -w require 5.001; $SIG{__WARN__} = sub { if ($_[0] =~ /uninit/) { die $@; } else { warn $@; } }; 4.10) Why doesn't Perl interpret my octal data octally? Perl only understands octal and hex numbers as such when they occur as literals in your program. If they are read in from somewhere and assigned, then no automatic conversion takes place. You must explicitly use oct() or hex() if you want this kind of thing to happen. Actually, oct() knows to interpret both hex and octal numbers, while hex only converts hexadecimal ones. For example: { print "What mode would you like? "; $mode = ; $mode = oct($mode); unless ($mode) { print "You can't really want mode 0!\n"; redo; } chmod $mode, $file; } Without the octal conversion, a requested mode of 755 would turn into 01363, yielding bizarre file permissions of --wxrw--wt. If you want something that handles decimal, octal and hex input, you could follow the suggestion in the man page and use: $val = oct($val) if $val =~ /^0/; 4.11) How can I compare two date strings? If the dates are in an easily parsed, predetermined format, then you can break them up into their component parts and call &timelocal from the distributed perl library. If the date strings are in arbitrary formats, however, it's probably easier to use the getdate program from the Cnews distribution, since it accepts a wide variety of dates. Note that in either case the return values you will really be comparing will be the total time in seconds as returned by time(). Here's a getdate function for perl that's not very efficient; you can do better than this by sending it many dates at once or modifying getdate to behave better on a pipe. Beware the hardcoded pathname. sub getdate { local($_) = shift; s/-(\d{4})$/+$1/ || s/\+(\d{4})$/-$1/; # getdate has broken timezone sign reversal! $_ = `/usr/local/lib/news/newsbin/getdate '$_'`; chop; $_; } You can also get the GetDate extension module that's actually the C code linked into perl from wherever fine Perl extensions are given away. It's about 50x faster. If you can't find it elsewhere, I usually keep a copy on perl.com for ftp, since I (Tom) ported it. Richard Ohnemus actually has a getdate.y for use with the Perl yacc (see question 3.3 "Is there a yacc for Perl?"). You might also consider using these: date.pl - print dates how you want with the sysv +FORMAT method date.shar - routines to manipulate and calculate dates ftp-chat2.shar - updated version of ftpget. includes library and demo programs getdate.shar - returns number of seconds since epoch for any given date ptime.shar - print dates how you want with the sysv +FORMAT method You probably want 'getdate.shar'... these and other files can be ftp'd from the /pub/perl/scripts directory on ftp.cis.ufl.edu. See the README file in the /pub/perl directory for time and the European mirror site details. 4.12) How can I find the Julian Day? Here's an example of a Julian Date function provided by Thomas R. Kimpton*. #!/usr/local/bin/perl @theJulianDate = ( 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ); #************************************************************************ #**** Return 1 if we are after the leap day in a leap year. ***** #************************************************************************ sub leapDay { my($year,$month,$day) = @_; if (year % 4) { return(0); } if (!(year % 100)) { # years that are multiples of 100 # are not leap years if (year % 400) { # unless they are multiples of 400 return(0); } } if (month < 2) { return(0); } elsif ((month == 2) && (day < 29)) { return(0); } else { return(1); } } #************************************************************************ #**** Pass in the date, in seconds, of the day you want the ***** #**** julian date for. If your localtime() returns the year day ***** #**** return that, otherwise figure out the julian date. ***** #************************************************************************ sub julianDate { my($dateInSeconds) = @_; my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime($dateInSeconds); if (defined($yday)) { return($yday+1); } else { return($theJulianDate[$mon] + $mday + &leapDay($year,$mon,$mday)); } } print "Today's julian date is: ",&julianDate(time),"\n"; 4.13) Does perl have a round function? What about ceil() and floor()? Perl does not have an explicit round function. However, it is very simple to create a rounding function. Since the int() function simply removes the decimal value and returns the integer portion of a number, you can use sub round { my($number) = shift; return int($number + .5); } If you examine what this function is doing, you will see that any number greater than .5 will be increased to the next highest integer, and any number less than .5 will remain the current integer, which has the same effect as rounding. A slightly better solution, one which handles negative numbers as well, might be to change the return (above) to: return int($number + .5 * ($number <=> 0)); which will modify the .5 to be either positive or negative, based on the number passed into it. If you wish to round to a specific significant digit, you can use the printf function