PerlCategory:Programming languages
Perl, also Practical Extraction and Report Language (a backronym, see below), is a programming language released by Larry Wall on December 18, 1987 that borrows features from C, sed, awk, shell scripting (sh), and (to a lesser extent) from many other programming languages.
Implementation\nA huge collection of freely usable perl modules, ranging from advanced mathematics to database connectivity, networking and more, can be downloaded from a network of sites called CPAN, an acronym for Comprehensive Perl Archive Network. Most or all of the software on CPAN is also available under either the Artistic License, the GPL, or both. CPAN.pm is also the name of the Perl module that downloads and installs other Perl modules from one of the CPAN mirror sites: such installations can be done with interactive prompts, or can be fully automated. Although Perl has most of the ease-of-use features of an interpreted language, it does not strictly interpret and execute source code one line at a time. Rather, perl (the program) first compiles an entire program to an intermediate byte code (much like Java's byte code), optimizing as it goes, and then executes that byte code. It is possible to compile a Perl program to byte code to save the compilation step on later executions, though the "interpreter" is still needed to execute that code.Current version\nThe current version, 5.8.4, includes Unicode support. Development of the next major release, Perl 6, is also underway. It will run on Parrot, a virtual machine which is being developed as a possible multi-language target architecture.Control structures\nThe basic control structures do not differ greatly from those used in the C or Java programming languages: Loopswhile (Boolean expression) {\n statement(s)\n }
do {\n statement(s)\n } while (Boolean expression);
do {\n statement(s)\n } until (Boolean expression);
for (initialisation ; termination condition ; incrementing expr) {\n statement(s)\n }
foreach ( array ) {\n statement(s)\n }
\nIf-then-statements
if (Boolean expression) {\n statement(s)\n }
unless (Boolean expression) {\n '\'statement(s)''\n }
if (Boolean expression) {\n statement(s)\n } else {\n statement(s)\n }
if (Boolean expression) {\n statement(s)\n } elsif (Boolean expression) {\n statement(s)\n }
\nFor one-line statements, "until", "while" and "if" can also be used as follows:\n statement(s) until Boolean expression;\n statement(s) while Boolean expression;\n statement(s) if Boolean expression;
Subroutines\nSubroutines in Perl can be specified with the keyword 'sub'. Variables passed to a subroutine appear in the subroutine as elements of the local (to the subroutine) scalar array @_. Calling a subroutine with three scalar variables results in array elements @_[0], @_[1], and @_[2] within the subroutine. Note that these elements would be referred to as the scalars $_[0], $_[1], and $_[2]. Also shift can be used, without specifying @_, to obtain each value. Changes to elements in the @_ array within the subroutine are reflected in the elements in the calling program. Subroutines naturally return the value of the last expression evaluated, though explicit use of the return statement is often encouraged for clarity. An example subroutine definition and call follows:sub cube\n {\n my $x = shift;\n $x * $x * $x;\n }\n ...\n $z = -4;\n $y = cube($z);\n print "$y\\n";
Named parameters can be simulated by passing a hash.
Perl and SQL databases\nDBI/DBD modules can be used to access most ANSI SQL databases,\nincluding MySQL, PostgreSQL and Oracle.Perl 5\nPerl5, the most current production version of perl, is an interpreter which processes the text of a Perl script at runtime. Thus, the debugger is invoked directly from the command line with\n\n perl -dw ScriptName.pl Argument1 ... ...\n\nNote that there is no limit to the number of arguments: Perl is polyadic; any number of arguments can be passed to any Perl subroutine, in general. This concept of "no arbitrary limits" is present in most other parts of the language as well. Perl can read a ten million byte string into a variable, if the machine has the memory for it. Perl 6\nPerl6 is currently under development, and is planned to separate parsing, compilation and runtime, making a virtual machine that is more attractive to developers looking to port other languages to the architecture. Parrot is the Perl6 runtime, and can be programmed at a low level in Parrot assembly language. Parrot has existed in a limited form since December 2003. An increasing number of languages have been implemented to various degrees for the Parrot to be 'compiled' to Parrot assembly language opcodes. Besides a subset of the planned Perl6, these include BASIC, Befunge, Cola, Forth, Jako, Ook, Plot, and even Python, Ruby, and Scheme.Perl code samples\nThe canonical "hello world" program would be:#!/usr/bin/perl -w\n print "Hello world\\n";The first line is the shebang, which indicates the interpreter for Unix-like operating systems. The second line prints the string 'Hello world' and a newline (like a person pressing 'Return' or 'Enter'). Some people humorously claim that Perl stands for "Pathologically Eclectic Rubbish Lister" due to its philosophy that there should be many ways to do the same thing, its growth by accretion, and its origins in report writing. There are many other jokes, including the annual Obfuscated Perl contest, which makes an arch virtue of Perl's syntactical flexibility. The following program, which prints a greeting that is modified by a regular expression, is a mild example of this pastime: # A sample Perl program\n $_ = "Hello, world! The magic number is 234542354.\\n";\n print;\n s/\\d+/-1/;\n print;Here is its output: Hello, world! The magic number is 234542354.\n Hello, world! The magic number is -1. Regular expressions with Perl examples\n
Name"Perl" was originally named "pearl", after the "pearl of great price" of Matthew 13:46. Larry Wall wanted to give the language a short name with positive connotations, and claims he looked at (and rejected) every three- and four-letter word in the dictionary. He even thought of naming it after his wife Gloria. Before the language's official release, Wall discovered that there was already a programming language named "pearl", and changed the spelling of the name. Several backronyms have been suggested, including the humorous Pathologically Eclectic Rubbish Lister. Practical Extraction and Report Language has prevailed in many of today's manuals, including the official Perl man pages. The name is normally capitalized ("Perl") when referring to the language, and uncapitalized ("perl") when referring to the interpreter program itself. (There is a saying in the Perl community that "Nothing but perl can parse Perl".) It is not appropriate to write "Perl" as "PERL" as it is not an acronym.Perl humor\n*Perl humour on wikibooks\n*State of the Onion 2003 (Larry Wall on Perl 6)\n*Larry Wall quotes\n*Lingua::Romana::Perligata - Write Perl in Latin!\n*Perl Purity TestSee also\n* Just another Perl hacker\n* Obfuscated Perl contest\n* POE -- Perl Object Environment\n* Fibonacci number program\n* Perl poetryExternal links\n* Perl.com\n* dmoz on Perl\n* Perl.org\n* Perl Mongers user group site\n* The Perl Monastery\n* ActiveState - Perl for Microsoft Windows platforms\n* IndigoStar, home of IndigoPerl, another distribution of Perl for the Microsoft Windows platform\n* CPAN - Comprehensive Perl Archive Network\n* Search the Comprehensive Perl Archive Network\n* Perl 6 development\n* Parrot virtual machine\n* Perl POD documentation\n* Scripting on the Lido Deck by Steve Silberman, Wired Magazine article about Perl Whirl 2000\n* Interview with Larry Wall on Perl (May 01, 1999)\n* Perl Timeline\n* First reference to "Perl" on UsenetBooks\n*Programming Perl (often called the Camel book) (read online)\n* Perl Cookbook (read online: 2nd edition 1st edition).\n*Learning Perl (also called the Llama book) \n\n\n\n\n\n\n\n\n\n\n\n\n |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) |
Perl, also Practical Extraction and Report Language (a 