A hash, or even associative array, is a map from either strings to scalars; a strings come known as keys & a scalars come known as values.
the lot variables come marked by a leading sigil,
which identifies a information nature and severity.
A equivalent title can be utilized for variables of different types,
while forgoing conflict.
$foo # the scalar
@foo # the list
%foo # the hash
Amounts come written in the common way;
strings come enclosed by quotes of various sort.
$n = 42;
$name = "joe";
$color = 'red';
The names can be written by list its elements,
separated by commas,
& enclosed by parentheses in which needed by operator precedence.
@scores = (32, 4Pentad, Xvi, 5);
The hash can be initialized from either the names of key/value pairs.
%favorite = (joe => 'red',
sam => 'blue');
Single elements of the names come accessed by providing the numerical
stock, within square brackets. Single values within the hash are
accessed by providing a corresponding key, within curly braces. The
$ sigil identifies a accessed element as a scalar.
$scores[2] # an element of @scores
$favorite# the value around %favorite
A total of elements within an array may be found by evalulating the
array inside scalar context.
$count = @friends;
There are two or three functions that operate entire hashes.
@list = keys %address;
@addresses = values %address;
Control structures
Perl has many sort of control structures. It has prevent-oriented control structures, similar to victims in the C & Java programming languages. Conditions come surrounded by parentheses, & restricted obstructs come surrounded by braces:
label patch ( cond ) label patch ( cond ) label for ( init-expr ; cond-expr ; incr-expr ) label foreach volt-ampere ( names ) label foreach volt-ampere ( listing ) whenever ( cond ) in case ( cond ) in case ( cond )
In which just one statement is existence restricted, statement modifiers provide the lightly syntax:
statement whenever cond ;
statement unless cond ;
statement patch cond ;
statement until cond ;
statement foreach listing ;
Short-circuit logical operators come normally wont to consequence control flow at a expression level:
expr & expr
expr or even expr
This is especially utile because Perl treats a flow control keywords go to, run, next & previous when expressions, when several more languages assume the children statements.
Perl as well has deuce inexplicit looping constructs:
outcomes = grep list
outcomes = map list
grep comes back a lot elements of listings for which a restricted prevent evaluates to avowedly.
map evaluates a restricted prevent for every element of listing & comes back the listings of the resultant values. These constructs enable the elementary functional programming style.
No switch (multi-way branch) statement within Perl Cinque. a Perl documentation describes a half-pack shipway to achieve the equivalent symptom by applying more control structures, none completely acceptable.
The super general & flexible switch statement has been designed for Perl 6. A Switch module makes virtually all of the functionality of the Perl Captain hicks switch available to Perl Phoebe computer software.
Perl includes the goto label statement, however these are virtually never utilized. These are considered unfortunate neglect practise, the implementation is slow, & situations in which a goto is known as for even withwithin more languages either tend does'nt to occur in Perl or come better handled by having more control structures, like tagged loops.
There exists as well the goto &sub statement that performs a tail call.
It ends a todays routine & immediately calls a specified sub.
Utilize of this form is unfeeling accepted however unusual because these are seldom required.
Subroutines
Subroutines are defined sustaining a sub keyword,
& invoked only by naming the two.
Function definitions will come out anywhere in the program.
Parentheses come involved for calls that precede a definition.
foo();
sub foo foo;
a listings of arguments can be provided when the subprogram title.
Arguments can be scalars, lists, or even hashes.
foo $a, @b, %c;
the parameters to a function require non exist when declared as to either total or even nature and severity;
as a matter of fact, it will change from either call for for to call.
Arrays come expanded to their elements,
hashes come expanded to the listings of key/value pairs,
& a whole lot is passed into a subprogram when of these uniform listings of scalars.
Whatever arguments come passed come available to the routine in the favorite array @_.
A elements of @_ come aliased to the actual arguments;
changing an element of @_ changes a corresponding argument.
Elements of @_ can be accessed by subscripting it in the common way.
$_[0], $_[1]
Even so, a sequent code may be hard to understand,
& a parameters stand pass-by-information semantics,
which can be undesirable.
Of these most common idiom is to assign @_ to the listing of known as variables.
($a, $b, $c) = @_;
This results two mnemotechnical parameter list & pass-by-value sematics.
A second idiom is to shift parameters slay of @_.
This is especially most common once a subprogram requires just of these argument.
$a = shift;
Procedure might go to values.
go to 42, $x, @y, %z;
In case the subprogram doesn't exit via a go to statement,
so it comes back a previous expression evaluated in a procedure immune system.
Arrays & hashes in the go to value come expanded to lists of scalars,
even as it is for arguments.
A returned expression is evaluated in the career context of the routine;
this potty surprise a innocent.
sub listing sub array $a = listing; # is restored 6 - survive element of list
$a = array; # comes back Three - total of elements around list
@the = names; # is restored (Quaternity, V, Sextet)
@the = array; # is restored (Iv, Phoebe, Sextet)
A wantarray keyword might detect a nature and severity of context a work is known as around.
sub either $a = either; # is restored "Oranges"
@the = either; # is restored (Unity, Deuce)
Regular expressions
the Perl language includes a specialised syntax for writing regular expressions (REs), and a interpreter contains an engine for matching strings to regular expressions. the regular expression engine utilizes a backtracking algorithm, extending its capabilities from elementary pattern matching to string capture & substitution.
A Perl regular expression syntax was originally taken from either Unix Version 8 regular expressions. Still, it diverged prior to a number 1 release of Perl, & has since grownup to include several additional features.
A m// (match) operator introduces the regular expression match. (A leading m can be omitted for brevity.) In the simplest example, an expression like
$x =~ m/abc/
evaluates to avowedly iff the string $x matches the regular expression abc. Capturing the matched string may be handle surrounding a portion of the regular expression using parentheses & evaluating it inside listings context. This is extra interesting for system that may match multiple strings:
($matched) = $x =~ m/a(.)c/; # capture a character between 'the' & 'c'
A s/// (substitute) operator specifies the look for & replenish operation:
$x =~ s/abc/aBc/; # upcase a b
Perl regular expressions potty require modifiers. Which are actually individual-letter postfix that modify a meaning of the expression:
$x =~ m/abc/i; # experience-insensitive pattern match
$x =~ s/abc/aBc/g; # spherical seek & replace
Regular expressions may be heavy & cryptic. This is because regular expression syntax is pleasantly compact, typically applying individual characters or even character pairs to represent its operations. Perl will bring relief from either a condition by owning a /x modifer, which allows computer programmer to place whitespace & comments in regular expressions:
$x =~ m/a # match 'the'
. # match any character
hundred # match 'c'
/x;
1 most common utilize of regular expressions is to specify delimiters for the split operator:
@words = split m/,/, $line; # divide $line into comma-separated values
A split operator complements string capture. String capture is restored strings that match a regular expression, split is restored strings that don't match a RE.
Look at too Perl regular expression examples.
Database interfaces
Perl is widely favorite for database applications.
Its text treating facilities come expert for getting SQL interrogation;
arrays, hashes & automatic memory management produce it convenient to collect & run a returned information.
Around early versions of Perl, database interfaces were created by relinking the interpreter by using a client-side database library. This was somewhat clumsy; a particular condition was that the resultant perl workable was restricted to applying just the a single database interface that it was linked to. As well, relinking a interpreter was sufficiently hard that it was simply done for two or three of the first & widely utilized databases.
Within Perl Cinque, database interfaces come implemented by Perl DBI modules. A DBI (Database Interface) module presents one, database-independent interface to Perl applications, spell a DBD:: (Database Driver) modules treat a details of accessing occasionally Fifty different databases. There are DBD:: drivers for virtually all ANSI SQL databases.
Language design
A project of Perl may be understood as a response to iii wide trends in the computer industry: falling devices costs, rising labor costs, & forward compiler technology. Several earliest machine-oriented language, like Fortran and C, were designed to make effective have of expensive hardware. Inside direct contrast, Perl is designed to produce effective have of expensive programmer.
Perl has numerous features that ease a coder's project at a expense of greater CPU & memory requirements. These include automatic memory management; dynamic typing; strings, lists, & hashes; regular expressions, and interpreted execution.
Larry Wall was trained as a linguist, & a project of Perl is a lot informed by linguistic information. Examples include Huffman coding (common constructions should became short), serious prevent-weighting (the significant references should come number one), & a big collection of language primitives. Perl favors language constructs that come natural for homo to scan & write, potentially in which it complicate a Perl interpreter.
Perl has features that trend lines the kind of programming paradigms, like procedural, functional, and object-oriented. At a equivalent period, Perl doesn't enforce any particular paradigm, or postulate a computer programmer to pick out among the children.
There is a wide practical bent to each a Perl language & a community & culture that surround it. A prolusion to Programming Perl begins, "Perl is a language for getting your job done". 1 symptom of this is that Perl is non the straighten out language. It includes features in case humans utilise the children, tolerates exceptions to its system, & employs heuristic program to resolve syntactic ambiguities.
Discussing a variant behaviour of built-integral functions within names & scalar context, a perlfunc(One) human site says,
In the main, it clean what wise shoppers desire, unless you desire consistency.
Perl has many catchword that convey aspects of its project & utilize. A single is ''There's other than of these way to get it on'' (TMTOWTDI - generally pronounced 'Tim Toady'). A second is Perl: a Swiss Army Chainsaw of Programing language. The declared project goal of Perl is to produce real life tasks easily & hard tasks imaginable. Perl has likewise been known as A Duct Tape of the Internet.
Opinion
Perl engenders hard feelings among two its advocate & its
knocker.
Pro
Coder world health organization rather Perl generally cite its power, expressiveness,
& ease of utilise. Perl will bring infrastructure for numerous common
programming tasks, like string & names processing. More tasks,
like memory management, come handled automatically and
transparently. Coder from either more languages to Perl often
buy that completely classes of problems that it use at times struggled by using in the
preceding good don't arise within Perl. When Larry Wall put it,
What is the healthy of Perl? Would it be non the healthy of a wall that people
stand stopped up banging their heads against?
Besides its practical rewards, numbers of computer programmer only seem to enjoy working around Perl. Early issues of [http://www.tpj.com The Perl Journal] got the report titled "What is Perl?" that concluded
Perl is fun. Around these times of self-self-seeking jargon, conflicting & unpredictable
standards, & proprietary systems that discourage peeking under the
hood, humans keep close at hand forgotten that programming is supposed to be
fun. We don't mean a satisfaction of seeing my easily-tuned programs
launder my bidding, however a literary work of originative writing that yields
victims software online. By owning Perl, a journeying is when gratifying when a destination ...
Whatever the reasons, there exists clearly a wide community of humans who
come passionate all about Perl, when evidenced per hundreds to thousands of modules
that use been contributed to CPAN, & a hundreds of project proposals that were
submitted when RFCs for Perl Vi.
Con
The most common complaint is that Perl is horrible. Particularly, its prodigious apply of punctuation put occasionally humans dispatch; Perl source code is for instance compared to "line noise".
Around [http://www.paulgraham.com/pypar.html The Python Paradox], Paul Graham both acknowledges and responds to this:
At a mention of horrible source code, population might course believe of
Perl. However a superficial ugliness of Perl is non a sort I personally mean.
Really ugliness is non harsh-seeking syntax, however with to build
software away from a wrongly conception.
A second criticism is that Perl is to a fault complex & compact, & that it leads to "write-only" code, that is, to code that is virtually impossible to know fallowing it has been written. These are, course, imaginable to write obscure code in any language, however Perl has possibly additional than a common part of curt, complex & arcane language constructs to exacerbate a condition. Perl supports numerous such features for backwards compatibility, & for utilize in which maintainability is expressly non the concern, like computer program that come entered & process directly on the command line.
A freewheeling language style that delights a select few Perl coder concerns others. For instance, a Perl Quint object model doesn't enforce information security: access to personal information is restricted single by convention, non a language itself. An object created within a only place might well exist as modified in another; there might not become any single place in which its state is definitively established. There are techniques for addressing these issues, however it is non-native & little utilized.
around the different level, one of the early Unix engineers from either Bell Labs has expressed surprise that anyone can write crucial applications in a language for which no promulgated specification.
Perl, when by having any intepreted language, is non effective at pinching for even-loops or more processor-bound tasks. around addition, computer program typically have extrthe memory than it would whenever written in a compiled language.
Embedding the Perl interpreter within the C program is non when elementary when it may exist as.
Calling C-language procedure from either Perl code, via a XS interface,
is extraordinarily complex (although a Inline::One hundred extension mostly eleviates this concern).
A few businesses balk at utilizing Perl because it either don't see or even might't abide its licensing terms. A select few worry that it won't exist as breathe to obtain trend lines for it. A few object to the fact that since it's an taken language, a source code for Perl software is typically seeable to users.
History
Larry Wall began operate within Perl in 1987, and freed version Ace.Nought to the comprehensive.sources.misc newsgroup in December 18, 1987. A language expanded quickly on top a next couple of years. Perl Ii, freed within 1988, featured a better regular expression engine. Perl Terzetto, freed inside 1989, added support for binary information.
Until 1991, the just documentation for Perl was one (more and more protracted) human website. Around 1991, Programming Perl (a Camel Book) was published, & became the de facto information for the language. At a equivalent instance, a Perl version total was bumped to Quartet, does'nt to mark a major vary in the language, however to identify the version that was documented per book.
Perl Quaternary went across the series of maintenance releases, culminating inside Perl Little joe.036 around 1993. At that point, Larry Wall abandoned Perl Four to commence operate in Perl Cinque. Perl Foursome remains at version Quartet.036 to this day.
Development of Perl V continued into 1994. A perl5-porters mailing listings was established within May 1994 to coordinate work in porting Perl Cinque to different platforms. It remains a primary forum for development, maintenance, & porting of Perl Quintuplet.
Perl Fin was freed in October 17, 1994. It was the about complete revision of the interpreter, & added several newly features to the language, including objects, information, packages, & modules. Importantly, modules provided a mechanism for extending a language forswearing modifying the interpreter. This allowed a core interpreter to stablize, just as it enabled average Perl computer programmer to add recently language features.
In October 26, 1995, the Comprehensive Perl Archive Network (CPAN) was established. CPAN occurs as collection of site that archive & distribute Perl sources, binary distributions, documentation, scripts, & modules. Originally, from each one CPAN places got to exist as accessed across its have Address; in todays world, a only Address http://www.cpan.org automatically redirects to the CPAN places.
When of 2005, Perl 5 is however existence actively maintained. It at present includes Unicode support. A latest production release is Perl Quintet.Eighter from decatur.Septenary.
At a 2000 Perl Conference Jon Orwant made the pack for a major fresh language initiative. This led to the guide to lead off operate in the redesign of the language, to become known as Perl 6. Proposals for newly language features were solicited from either a Perl community at prominent, & complete 300 RFCs were submitted.
Larry Wall spent the next couple of years swallowing a RFCs & synthesizing the babies into a logical framework for Perl Captain hicks. He has presented his project for Perl Sextet inside the series of documents known as apocalypses.
Around 2001, it was decided that Perl 6 would rerun in the cross-language virtual machine called Parrot. When of 2005, two Perl Sixer & Parrot come under active development.
CPAN
CPAN, the Comprehensive Perl Archive Network, occurs as collection of mirrored site that help as a primary archive & channel for Perl sources, distributions, documentation, scripts, &—especially—modules. These are ordinarily looked by using a look for engine http://search.cpan.org/.
There are presently in top 8,800 modules available on CPAN, contributed by across 2,500 authors. Modules come available for the wide kind of tasks, including advanced math, database connectivity, & networking. In essence all about in CPAN is freely available; great deal of a software system is licensed under either the Artistic License, the GPL, or each. Anyone might upload software system to CPAN via [http://pause.perl.org PAUSE], a Perl Authors Upload Server.
Modules in CPAN may be downloaded & installed by hand. All the same, these are park for modules to depend in more modules, & as punishment module dependencies by hand may be tedious. Each a [http://search.cpan.org/Perldoc?CPAN CPAN.pm] module (involved in a Perl distribution) & the improved [http://search.cpan.org/Perldoc?CPANPLUS CPANPLUS] module offers comm& lines installers that see module dependencies; It may be configured to automatically download & set up the module and, recursively, everthing modules that it takes.
Name
Perl was originally known as "Pearl", when "the pearl of great price" of Matthew 13:46. Larry Wall wanted to give the language a short title using caring connotations & claims he seemed at (& rejected) each 3- & 4-letter word in the lexicon. He possibly thought of naming it fallowing his married woman Gloria. Wall found prior to a language's official release that there was already the programing language known as PEARL and changed the spelling of the title.
A title is usually capitalized (Perl) after on to the language & uncapitalized (perl) whilst on to the interpreter program itself since Unix-prefer filesystems come experience sensitive. (There is a locution in the Perl community: "Only perl can parse Perl.") (Prior to a release of the number 1 edition of Programming Perl it wwhen common to refer to the language as perl; Randal L. Schwartz, however, forced the uppercase language name in the book to make the name stand out better when typeset. A example distinction was afterwards adopted per community.) These are non appropriate to write "PERL" when these are non really an acronym. A spelling of PERL all told caps is so utilized as a shibboleth for detecting community outsiders.
But, many backronyms have been suggested, including a humourous Pathologically Eclectic Rubbish Lister.
Too, Practical Extraction & Report Language has prevailed within numerous of now's manuals, including a official Perl man page. These are likewise uniform by owning a old title "Pearl": Practical Extraction & Report Language.
The Camel Symbol
Perl is usually symbolized by the camel, which was the symptom of the picture of camel book publishers O'Reilly Media chose as the cover picture of Programming Perl, which consequently acquired the name The Camel Book. O'Reilly owns a symbol as a trademark, however claims to utilise their legal rights simply as a measure of protecting a "integrity and impact of that symbol" [http://perl.oreilly.com/usage/]. Have of the symbol for non-commercial purposes is allowed & the Programming Republic of Perl logotype (view above) is provided for this purpose.
Fun with Perl
When using C, obfuscated code competitions are the popular feature of Perl culture. A annual Obfuscated Perl contest makes an arch virtue of Perl's syntactic flexibility. A as a consequence program prints a text "Just another Perl / Unix hacker", utilizing 32 cooccurring processes coordinated by pipes. The complete explanation is available on the [http://perl.plover.com/obfuscated/ author's Web site].
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p%p;hold off until$?;map%p;$_=$d[$q];sleep rand(Ii)if/\S/;print
Similar to obfuscated code however sustaining the different purpose, Perl Poetry is the practice of writing poems that potty actually exist as compiled by perl. This hobby is some unique to Perl due to the heavy total of regular English words utilized in the language. Recently verse form come regularly published in the Perl Monks site's [http://www.perlmonks.org/index.pl?node=Perl%20Poetry Perl Poetry] section.
An additional popular interest is Perl golf game. When using the physical sport the goal is to reduce the total of strokes that it requires to complete the particular objective, however on text "strokes" refers to keystrokes like than swings of the golf game club. The project, like "scan an input string and return the longest palindrome that it contains", is proposed & participants try to outdo both more by writing solutions that expect fewer and fewer characters of Perl source code.
A second tradition among Perl hackers is writing JAPHs, which are short obfuscated computer software that print out a sentence "Just another Perl hacker,". A "canonical" JAPH includes a comma at a prevent, although this is typically omitted, & numbers of variants on the theme keep close at hand been created (lesson: [http://www.perlmonks.org/index.pl?node_id=292135], which prints "Just Another Perl Pirate!").
Of these interesting Perl module is Tongue::Romana::Perligata. This module translates a source code of a script that utilizes it from either Latinside into Perl, permitting the software engineer to write feasible computer software in Latin.
A Perl community has placed aside a "Acme" namespace for even modules that are fun or experimental around nature and severity. A select few of the Acme modules come deliberately implemented inside amusing ways. A select few examples:
[http://search.cpan.org/dist/Acme-Hello/ Acme::Hello] simplifies the run of writing a "Hello, World!" program
[http://search.cpan.org/dist/Acme-Currency/ Acme::Currency] allows wise shoppers to vary a "$" prefix for scalar variables to another character
[http://search.cpan.org/dist/Acme-ProgressBar/ Acme::ProgressBar] is the dreadfully ineffective way to show progress for a task
[http://search.cpan.org/dist/Acme-VerySign/ Acme::VerySign] satirizes a widely-criticized VeriSign Site Finder service
[http://search.cpan.org/~dconway/Acme-Don-t-1.01/t.pm Acme::Don't] implements a logical opposite of the wash keyword—don't, which doesn't execute a provided prevent.
View also
[http://wikibooks.org/wiki/Programming:Perl_humour Perl humour on wikibooks]
[http://www.cmpe.boun.edu.tr/~kosar/other/lwall.html Larry Wall quotes]
[http://search.cpan.org/perldoc?Lingua::Romana::Perligata Lingua::Romana::Perligata - Write Perl in Latin!]
[http://www.perlmonks.org/index.pl?node_id=253797 A tutorial on Perligata]
[http://www.softpanorama.org/Bulletin/Humor/humor092.html Perl Purity Test]