Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | =head1 NAME |
2 | ||
3 | perlfaq1 - General Questions About Perl ($Revision: 1.19 $, $Date: 2005/12/31 00:54:37 $) | |
4 | ||
5 | =head1 DESCRIPTION | |
6 | ||
7 | This section of the FAQ answers very general, high-level questions | |
8 | about Perl. | |
9 | ||
10 | =head2 What is Perl? | |
11 | ||
12 | Perl is a high-level programming language with an eclectic heritage | |
13 | written by Larry Wall and a cast of thousands. It derives from the | |
14 | ubiquitous C programming language and to a lesser extent from sed, | |
15 | awk, the Unix shell, and at least a dozen other tools and languages. | |
16 | Perl's process, file, and text manipulation facilities make it | |
17 | particularly well-suited for tasks involving quick prototyping, system | |
18 | utilities, software tools, system management tasks, database access, | |
19 | graphical programming, networking, and world wide web programming. | |
20 | These strengths make it especially popular with system administrators | |
21 | and CGI script authors, but mathematicians, geneticists, journalists, | |
22 | and even managers also use Perl. Maybe you should, too. | |
23 | ||
24 | =head2 Who supports Perl? Who develops it? Why is it free? | |
25 | ||
26 | The original culture of the pre-populist Internet and the deeply-held | |
27 | beliefs of Perl's author, Larry Wall, gave rise to the free and open | |
28 | distribution policy of perl. Perl is supported by its users. The | |
29 | core, the standard Perl library, the optional modules, and the | |
30 | documentation you're reading now were all written by volunteers. See | |
31 | the personal note at the end of the README file in the perl source | |
32 | distribution for more details. See L<perlhist> (new as of 5.005) | |
33 | for Perl's milestone releases. | |
34 | ||
35 | In particular, the core development team (known as the Perl Porters) | |
36 | are a rag-tag band of highly altruistic individuals committed to | |
37 | producing better software for free than you could hope to purchase for | |
38 | money. You may snoop on pending developments via the archives at | |
39 | http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/ | |
40 | and http://archive.develooper.com/perl5-porters@perl.org/ | |
41 | or the news gateway nntp://nntp.perl.org/perl.perl5.porters or | |
42 | its web interface at http://nntp.perl.org/group/perl.perl5.porters , | |
43 | or read the faq at http://simon-cozens.org/writings/p5p-faq , | |
44 | or you can subscribe to the mailing list by sending | |
45 | perl5-porters-request@perl.org a subscription request | |
46 | (an empty message with no subject is fine). | |
47 | ||
48 | While the GNU project includes Perl in its distributions, there's no | |
49 | such thing as "GNU Perl". Perl is not produced nor maintained by the | |
50 | Free Software Foundation. Perl's licensing terms are also more open | |
51 | than GNU software's tend to be. | |
52 | ||
53 | You can get commercial support of Perl if you wish, although for most | |
54 | users the informal support will more than suffice. See the answer to | |
55 | "Where can I buy a commercial version of perl?" for more information. | |
56 | ||
57 | =head2 Which version of Perl should I use? | |
58 | ||
59 | (contributed by brian d foy) | |
60 | ||
61 | There is often a matter of opinion and taste, and there isn't any | |
62 | one answer that fits anyone. In general, you want to use either | |
63 | the current stable release, or the stable release immediately prior | |
64 | to that one. Currently, those are perl5.8.x and perl5.6.x, respectively. | |
65 | ||
66 | Beyond that, you have to consider several things and decide which | |
67 | is best for you. | |
68 | ||
69 | =over 4 | |
70 | ||
71 | =item * | |
72 | ||
73 | If things aren't broken, upgrading perl may break | |
74 | them (or at least issue new warnings). | |
75 | ||
76 | =item * | |
77 | ||
78 | The latest versions of perl have more bug fixes. | |
79 | ||
80 | =item * | |
81 | ||
82 | The Perl community is geared toward supporting the most | |
83 | recent releases, so you'll have an easier time finding help for | |
84 | those. | |
85 | ||
86 | =item * | |
87 | ||
88 | Versions prior to perl5.004 had serious security problems with | |
89 | buffer overflows, and in some cases have CERT advisories (for | |
90 | instance, http://www.cert.org/advisories/CA-1997-17.html ). | |
91 | ||
92 | =item * | |
93 | ||
94 | The latest versions are probably the least deployed and | |
95 | widely tested, so you may want to wait a few months after their | |
96 | release and see what problems others have if you are risk averse. | |
97 | ||
98 | =item * | |
99 | ||
100 | The immediate, previous releases (i.e. perl5.6.x ) are usually | |
101 | maintained for a while, although not at the same level as the | |
102 | current releases. | |
103 | ||
104 | =item * | |
105 | ||
106 | No one is actively supporting perl4.x. Five years ago it was | |
107 | a dead camel carcass (according to this document). Now it's barely | |
108 | a skeleton as its whitewashed bones have fractured or eroded. | |
109 | ||
110 | =item * | |
111 | ||
112 | There is no perl6.x for the next couple of years. Stay tuned, | |
113 | but don't worry that you'll have to change major versions of Perl | |
114 | soon (i.e. before 2006). | |
115 | ||
116 | =item * | |
117 | ||
118 | There are really two tracks of perl development: a | |
119 | maintenance version and an experimental version. The | |
120 | maintenance versions are stable, and have an even number | |
121 | as the minor release (i.e. perl5.8.x, where 8 is the minor | |
122 | release). The experimental versions may include features that | |
123 | don't make it into the stable versions, and have an odd number | |
124 | as the minor release (i.e. perl5.9.x, where 9 is the minor release). | |
125 | ||
126 | =back | |
127 | ||
128 | ||
129 | =head2 What are perl4, perl5, or perl6? | |
130 | ||
131 | (contributed by brian d foy) | |
132 | ||
133 | In short, perl4 is the past, perl5 is the present, and perl6 is the | |
134 | future. | |
135 | ||
136 | The number after perl (i.e. the 5 after perl5) is the major release | |
137 | of the perl interpreter as well as the version of the language. Each | |
138 | major version has significant differences that earlier versions cannot | |
139 | support. | |
140 | ||
141 | The current major release of Perl is perl5, and was released in 1994. | |
142 | It can run scripts from the previous major release, perl4 (March 1991), | |
143 | but has significant differences. It introduced the concept of references, | |
144 | complex data structures, and modules. The perl5 interpreter was a | |
145 | complete re-write of the previous perl sources. | |
146 | ||
147 | Perl6 is the next major version of Perl, but it's still in development | |
148 | in both its syntax and design. The work started in 2002 and is still | |
149 | ongoing. Many of the most interesting features have shown up in the | |
150 | latest versions of perl5, and some perl5 modules allow you to use some | |
151 | perl6 syntax in your programs. You can learn more about perl6 at | |
152 | http://dev.perl.org/perl6/ . | |
153 | ||
154 | See L<perlhist> for a history of Perl revisions. | |
155 | ||
156 | =head2 What is Ponie? | |
157 | ||
158 | At The O'Reilly Open Source Software Convention in 2003, Artur | |
159 | Bergman, Fotango, and The Perl Foundation announced a project to | |
160 | run perl5 on the Parrot virtual machine named Ponie. Ponie stands for | |
161 | Perl On New Internal Engine. The Perl 5.10 language implementation | |
162 | will be used for Ponie, and there will be no language level | |
163 | differences between perl5 and ponie. Ponie is not a complete rewrite | |
164 | of perl5. | |
165 | ||
166 | For more details, see http://www.poniecode.org/ | |
167 | ||
168 | =head2 What is perl6? | |
169 | ||
170 | At The Second O'Reilly Open Source Software Convention, Larry Wall | |
171 | announced Perl6 development would begin in earnest. Perl6 was an oft | |
172 | used term for Chip Salzenberg's project to rewrite Perl in C++ named | |
173 | Topaz. However, Topaz provided valuable insights to the next version | |
174 | of Perl and its implementation, but was ultimately abandoned. | |
175 | ||
176 | If you want to learn more about Perl6, or have a desire to help in | |
177 | the crusade to make Perl a better place then peruse the Perl6 developers | |
178 | page at http://dev.perl.org/perl6/ and get involved. | |
179 | ||
180 | Perl6 is not scheduled for release yet, and Perl5 will still be supported | |
181 | for quite awhile after its release. Do not wait for Perl6 to do whatever | |
182 | you need to do. | |
183 | ||
184 | "We're really serious about reinventing everything that needs reinventing." | |
185 | --Larry Wall | |
186 | ||
187 | =head2 How stable is Perl? | |
188 | ||
189 | Production releases, which incorporate bug fixes and new functionality, | |
190 | are widely tested before release. Since the 5.000 release, we have | |
191 | averaged only about one production release per year. | |
192 | ||
193 | Larry and the Perl development team occasionally make changes to the | |
194 | internal core of the language, but all possible efforts are made toward | |
195 | backward compatibility. While not quite all perl4 scripts run flawlessly | |
196 | under perl5, an update to perl should nearly never invalidate a program | |
197 | written for an earlier version of perl (barring accidental bug fixes | |
198 | and the rare new keyword). | |
199 | ||
200 | =head2 Is Perl difficult to learn? | |
201 | ||
202 | No, Perl is easy to start learning--and easy to keep learning. It looks | |
203 | like most programming languages you're likely to have experience | |
204 | with, so if you've ever written a C program, an awk script, a shell | |
205 | script, or even a BASIC program, you're already partway there. | |
206 | ||
207 | Most tasks only require a small subset of the Perl language. One of | |
208 | the guiding mottos for Perl development is "there's more than one way | |
209 | to do it" (TMTOWTDI, sometimes pronounced "tim toady"). Perl's | |
210 | learning curve is therefore shallow (easy to learn) and long (there's | |
211 | a whole lot you can do if you really want). | |
212 | ||
213 | Finally, because Perl is frequently (but not always, and certainly not by | |
214 | definition) an interpreted language, you can write your programs and test | |
215 | them without an intermediate compilation step, allowing you to experiment | |
216 | and test/debug quickly and easily. This ease of experimentation flattens | |
217 | the learning curve even more. | |
218 | ||
219 | Things that make Perl easier to learn: Unix experience, almost any kind | |
220 | of programming experience, an understanding of regular expressions, and | |
221 | the ability to understand other people's code. If there's something you | |
222 | need to do, then it's probably already been done, and a working example is | |
223 | usually available for free. Don't forget the new perl modules, either. | |
224 | They're discussed in Part 3 of this FAQ, along with CPAN, which is | |
225 | discussed in Part 2. | |
226 | ||
227 | =head2 How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl? | |
228 | ||
229 | Favorably in some areas, unfavorably in others. Precisely which areas | |
230 | are good and bad is often a personal choice, so asking this question | |
231 | on Usenet runs a strong risk of starting an unproductive Holy War. | |
232 | ||
233 | Probably the best thing to do is try to write equivalent code to do a | |
234 | set of tasks. These languages have their own newsgroups in which you | |
235 | can learn about (but hopefully not argue about) them. | |
236 | ||
237 | Some comparison documents can be found at http://www.perl.com/doc/FMTEYEWTK/versus/ | |
238 | if you really can't stop yourself. | |
239 | ||
240 | =head2 Can I do [task] in Perl? | |
241 | ||
242 | Perl is flexible and extensible enough for you to use on virtually any | |
243 | task, from one-line file-processing tasks to large, elaborate systems. | |
244 | For many people, Perl serves as a great replacement for shell scripting. | |
245 | For others, it serves as a convenient, high-level replacement for most of | |
246 | what they'd program in low-level languages like C or C++. It's ultimately | |
247 | up to you (and possibly your management) which tasks you'll use Perl | |
248 | for and which you won't. | |
249 | ||
250 | If you have a library that provides an API, you can make any component | |
251 | of it available as just another Perl function or variable using a Perl | |
252 | extension written in C or C++ and dynamically linked into your main | |
253 | perl interpreter. You can also go the other direction, and write your | |
254 | main program in C or C++, and then link in some Perl code on the fly, | |
255 | to create a powerful application. See L<perlembed>. | |
256 | ||
257 | That said, there will always be small, focused, special-purpose | |
258 | languages dedicated to a specific problem domain that are simply more | |
259 | convenient for certain kinds of problems. Perl tries to be all things | |
260 | to all people, but nothing special to anyone. Examples of specialized | |
261 | languages that come to mind include prolog and matlab. | |
262 | ||
263 | =head2 When shouldn't I program in Perl? | |
264 | ||
265 | When your manager forbids it--but do consider replacing them :-). | |
266 | ||
267 | Actually, one good reason is when you already have an existing | |
268 | application written in another language that's all done (and done | |
269 | well), or you have an application language specifically designed for a | |
270 | certain task (e.g. prolog, make). | |
271 | ||
272 | For various reasons, Perl is probably not well-suited for real-time | |
273 | embedded systems, low-level operating systems development work like | |
274 | device drivers or context-switching code, complex multi-threaded | |
275 | shared-memory applications, or extremely large applications. You'll | |
276 | notice that perl is not itself written in Perl. | |
277 | ||
278 | The new, native-code compiler for Perl may eventually reduce the | |
279 | limitations given in the previous statement to some degree, but understand | |
280 | that Perl remains fundamentally a dynamically typed language, not | |
281 | a statically typed one. You certainly won't be chastised if you don't | |
282 | trust nuclear-plant or brain-surgery monitoring code to it. And Larry | |
283 | will sleep easier, too--Wall Street programs not withstanding. :-) | |
284 | ||
285 | =head2 What's the difference between "perl" and "Perl"? | |
286 | ||
287 | One bit. Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to | |
288 | signify the language proper and "perl" the implementation of it, | |
289 | i.e. the current interpreter. Hence Tom's quip that "Nothing but perl | |
290 | can parse Perl." You may or may not choose to follow this usage. For | |
291 | example, parallelism means "awk and perl" and "Python and Perl" look | |
292 | OK, while "awk and Perl" and "Python and perl" do not. But never | |
293 | write "PERL", because perl is not an acronym, apocryphal | |
294 | folklore and post-facto expansions notwithstanding. | |
295 | ||
296 | =head2 Is it a Perl program or a Perl script? | |
297 | ||
298 | Larry doesn't really care. He says (half in jest) that "a script is | |
299 | what you give the actors. A program is what you give the audience." | |
300 | ||
301 | Originally, a script was a canned sequence of normally interactive | |
302 | commands--that is, a chat script. Something like a UUCP or PPP chat | |
303 | script or an expect script fits the bill nicely, as do configuration | |
304 | scripts run by a program at its start up, such F<.cshrc> or F<.ircrc>, | |
305 | for example. Chat scripts were just drivers for existing programs, | |
306 | not stand-alone programs in their own right. | |
307 | ||
308 | A computer scientist will correctly explain that all programs are | |
309 | interpreted and that the only question is at what level. But if you | |
310 | ask this question of someone who isn't a computer scientist, they might | |
311 | tell you that a I<program> has been compiled to physical machine code | |
312 | once and can then be run multiple times, whereas a I<script> must be | |
313 | translated by a program each time it's used. | |
314 | ||
315 | Perl programs are (usually) neither strictly compiled nor strictly | |
316 | interpreted. They can be compiled to a byte-code form (something of a | |
317 | Perl virtual machine) or to completely different languages, like C or | |
318 | assembly language. You can't tell just by looking at it whether the | |
319 | source is destined for a pure interpreter, a parse-tree interpreter, | |
320 | a byte-code interpreter, or a native-code compiler, so it's hard to give | |
321 | a definitive answer here. | |
322 | ||
323 | Now that "script" and "scripting" are terms that have been seized by | |
324 | unscrupulous or unknowing marketeers for their own nefarious purposes, | |
325 | they have begun to take on strange and often pejorative meanings, | |
326 | like "non serious" or "not real programming". Consequently, some Perl | |
327 | programmers prefer to avoid them altogether. | |
328 | ||
329 | =head2 What is a JAPH? | |
330 | ||
331 | These are the "just another perl hacker" signatures that some people | |
332 | sign their postings with. Randal Schwartz made these famous. About | |
333 | 100 of the earlier ones are available from | |
334 | http://www.cpan.org/misc/japh . | |
335 | ||
336 | =head2 Where can I get a list of Larry Wall witticisms? | |
337 | ||
338 | Over a hundred quips by Larry, from postings of his or source code, | |
339 | can be found at http://www.cpan.org/misc/lwall-quotes.txt.gz . | |
340 | ||
341 | =head2 How can I convince my sysadmin/supervisor/employees to use version 5/5.6.1/Perl instead of some other language? | |
342 | ||
343 | If your manager or employees are wary of unsupported software, or | |
344 | software which doesn't officially ship with your operating system, you | |
345 | might try to appeal to their self-interest. If programmers can be | |
346 | more productive using and utilizing Perl constructs, functionality, | |
347 | simplicity, and power, then the typical manager/supervisor/employee | |
348 | may be persuaded. Regarding using Perl in general, it's also | |
349 | sometimes helpful to point out that delivery times may be reduced | |
350 | using Perl compared to other languages. | |
351 | ||
352 | If you have a project which has a bottleneck, especially in terms of | |
353 | translation or testing, Perl almost certainly will provide a viable, | |
354 | quick solution. In conjunction with any persuasion effort, you | |
355 | should not fail to point out that Perl is used, quite extensively, and | |
356 | with extremely reliable and valuable results, at many large computer | |
357 | software and hardware companies throughout the world. In fact, | |
358 | many Unix vendors now ship Perl by default. Support is usually | |
359 | just a news-posting away, if you can't find the answer in the | |
360 | I<comprehensive> documentation, including this FAQ. | |
361 | ||
362 | See http://www.perl.org/advocacy/ for more information. | |
363 | ||
364 | If you face reluctance to upgrading from an older version of perl, | |
365 | then point out that version 4 is utterly unmaintained and unsupported | |
366 | by the Perl Development Team. Another big sell for Perl5 is the large | |
367 | number of modules and extensions which greatly reduce development time | |
368 | for any given task. Also mention that the difference between version | |
369 | 4 and version 5 of Perl is like the difference between awk and C++. | |
370 | (Well, OK, maybe it's not quite that distinct, but you get the idea.) | |
371 | If you want support and a reasonable guarantee that what you're | |
372 | developing will continue to work in the future, then you have to run | |
373 | the supported version. As of December 2003 that means running either | |
374 | 5.8.2 (released in November 2003), or one of the older releases like | |
375 | 5.6.2 (also released in November 2003; a maintenance release to let perl | |
376 | 5.6 compile on newer systems as 5.6.1 was released in April 2001) or | |
377 | 5.005_03 (released in March 1999), | |
378 | although 5.004_05 isn't that bad if you B<absolutely> need such an old | |
379 | version (released in April 1999) for stability reasons. | |
380 | Anything older than 5.004_05 shouldn't be used. | |
381 | ||
382 | Of particular note is the massive bug hunt for buffer overflow | |
383 | problems that went into the 5.004 release. All releases prior to | |
384 | that, including perl4, are considered insecure and should be upgraded | |
385 | as soon as possible. | |
386 | ||
387 | In August 2000 in all Linux distributions a new security problem was | |
388 | found in the optional 'suidperl' (not built or installed by default) | |
389 | in all the Perl branches 5.6, 5.005, and 5.004, see | |
390 | http://www.cpan.org/src/5.0/sperl-2000-08-05/ | |
391 | Perl maintenance releases 5.6.1 and 5.8.0 have this security hole closed. | |
392 | Most, if not all, Linux distribution have patches for this | |
393 | vulnerability available, see http://www.linuxsecurity.com/advisories/ , | |
394 | but the most recommendable way is to upgrade to at least Perl 5.6.1. | |
395 | ||
396 | =head1 AUTHOR AND COPYRIGHT | |
397 | ||
398 | Copyright (c) 1997-2006 Tom Christiansen, Nathan Torkington, and | |
399 | other authors as noted. All rights reserved. | |
400 | ||
401 | This documentation is free; you can redistribute it and/or modify it | |
402 | under the same terms as Perl itself. | |
403 | ||
404 | Irrespective of its distribution, all code examples here are in the public | |
405 | domain. You are permitted and encouraged to use this code and any | |
406 | derivatives thereof in your own programs for fun or for profit as you | |
407 | see fit. A simple comment in the code giving credit to the FAQ would | |
408 | be courteous but is not required. |