Content deleted Content added
Alexflatter (talk | contribs) No edit summary Tags: Manual revert Reverted |
Hot basket (talk | contribs) Bump latest preview version |
||
(34 intermediate revisions by 25 users not shown) | |||
Line 1:
{{Short description|Interpreted programming language first released in 1987}}
{{Other uses|Perl (disambiguation)}}
{{distinguish|PEARL (programming language)
{{Use mdy dates|date=September 2014}}
{{Infobox programming language
| name = Perl
| logo =
| paradigm = [[Multi-paradigm]]
| designer = [[Larry Wall]]
| developer = Larry Wall
| typing = [[Dynamic typing|Dynamic]]
| influenced = [[CoffeeScript]],{{citation needed|date=January 2016}} [[Groovy (programming language)|Groovy]],{{citation needed|date=February 2016}} [[JavaScript]], [[Julia (programming language)|Julia]], [[LPC (programming language)|LPC]], [[PHP]], [[Python (programming language)|Python]], [[Raku (programming language)|Raku]], [[Ruby (programming language)|Ruby]], [[PowerShell]]
| license = [[Artistic License|Artistic]] 1.0<ref name="artistic-1.0"/><ref name="artistic-1.0-git"/> or [[GNU General Public License]] version 1 or any later version<ref name="licensing"/>
| website = {{
| wikibooks = Perl Programming
| released = {{Start date and age|1987|12|18}}<ref name="perltimeline"/>
| latest release version = 5.
| latest release date = {{Start date and age|2025|07|03|df=yes}}
| latest preview version = 5.
| ▲|5.38.3<ref>{{cite web |url=https://www.nntp.perl.org/group/perl.perl5.porters/2025/01/msg269453.html |title=Perl 5.38.3 is now available |access-date=2025-01-19 |publisher=www.nntp.perl.org}}</ref> / {{Start date and age|mf=yes|2025|01|18|df=yes}}
}}▼
| influenced by=[[AWK]], [[BASIC]], [[C (programming language)|C]], [[C++]], [[Lisp (programming language)|Lisp]], [[sed]], [[Unix shell]]<ref>{{cite web|title=Programming is Hard, Let's Go Scripting...|last1=Wall|first1=Larry|author1-link=Larry Wall|date=December 12, 2007|url=https://www.perl.com/pub/2007/12/06/soto-11.html/|quote=All language designers have their occasional idiosyncracies. I’m just better at it than most.|access-date=April 14, 2019|archive-date=July 28, 2017|archive-url=https://web.archive.org/web/20170728023959/http://www.perl.com/pub/2007/12/06/soto-11.html|url-status=live}}</ref>
| programming language=[[C (programming language)|C]]
Line 56 ⟶ 48:
[[The Perl Foundation]] owns an alternative symbol, an onion, which it licenses to its subsidiaries, [[Perl Mongers]], [[PerlMonks]], Perl.org, and others.<ref name="onion">{{cite web |url=http://www.perlfoundation.org/perl_trademark |title=Perl Trademark |access-date=2011-01-09 |publisher=[[The Perl Foundation]] |archive-url=https://web.archive.org/web/20110503211915/http://www.perlfoundation.org/perl_trademark |archive-date=May 3, 2011 |url-status=dead |df=mdy-all}}</ref> The symbol is a [[visual pun]] on [[pearl onion]].<ref name="gillmore98">{{cite news |first=Dan |last=Gillmore |title=Republic Of Perl |date=1998-10-25 |url=https://www.chicagotribune.com/1998/10/25/republic-of-perl/ |work=Chicago Tribune |access-date=2011-01-10 |archive-date=April 30, 2011 |archive-url=https://web.archive.org/web/20110430031425/http://articles.chicagotribune.com/1998-10-25/news/9810250094_1_programmers-open-source-movement-programming-community |url-status=live}}</ref>
In 2024, a new camel logo for the language was published<ref name="2024logo">{{cite web | url=https://perladvent.org/2024/2024-12-23.html| title= A New Logo for Perl |access-date=2025-05-09 | publisher= Perl Advent Calendar 2024}}</ref> under a [[Creative Commons]] license by a small group of developers. While not an official logo, it is intended to represent both the language and the community and draws on Perl's longtime association with the camel from the O'Reilly book.
== History ==
Line 144 ⟶ 138:
| 2023-11-29
|-
| {{Version|
| 2025-
|-
| {{Version|
| 2025-
|-
|
| 2025-07-03
<!--
|-
| {{Version|
| 2025-XX-XX
-->▼
|-
| colspan="99" |<small>{{Version|lv|show=011111|}}</small>
▲-->
Perl 5.6 was released on March 22, 2000. Major changes included [[64-bit computing|64-bit]] support, [[Unicode]] string representation, support for files over 2 GiB, and the "our" keyword.<ref name="56delta">{{cite web |url=http://perldoc.perl.org/perl56delta.html |title=perl56delta - what's new for perl v5.6.0 |access-date=2011-01-21 |work=Perl 5 version 12.2 documentation |publisher=perldoc.perl.org |archive-date=February 2, 2011 |archive-url=https://web.archive.org/web/20110202135358/http://perldoc.perl.org/perl56delta.html |url-status=live}}</ref><ref name="561delta">{{cite web |url=http://perldoc.perl.org/perl561delta.html |title=perl56delta - what's new for perl v5.6.x |access-date=2011-01-21 |work=Perl 5 version 12.2 documentation |publisher=perldoc.perl.org |archive-date=November 18, 2010 |archive-url=https://web.archive.org/web/20101118101544/http://perldoc.perl.org/perl561delta.html |url-status=live}}</ref> When developing Perl 5.6, the decision was made to switch the [[software versioning|versioning]] scheme to one more similar to other open source projects; after 5.005_63, the next version became 5.5.640, with plans for development versions to have odd numbers and stable versions to have even numbers.<ref>{{Cite web |title=Perl {{!}} Definition, History, & Facts {{!}} Britannica |url=https://www.britannica.com/technology/Perl |access-date=2022-06-15 |website=www.britannica.com |language=en}}</ref>
Line 200 ⟶ 194:
Thesis work by [[Bradley M. Kuhn]], overseen by Wall, considered the possible use of the [[Java virtual machine]] as a runtime for Perl.<ref>{{cite thesis |last=Kuhn |first=Bradley M. |author-link=Bradley M. Kuhn |title=Considerations on Porting Perl to the Java Virtual Machine |type=MS thesis |publisher=University of Cincinnati |date=January 2001 |url=http://www.ebb.org/bkuhn/writings/technical/thesis/ |access-date=2008-06-28 |archive-date=March 21, 2008 |archive-url=https://web.archive.org/web/20080321164747/http://ebb.org/bkuhn/writings/technical/thesis/ |url-status=live}}</ref> Kuhn's thesis showed this approach to be problematic. In 2001, it was decided that Perl 6 would run on a cross-language [[virtual machine]] called [[Parrot virtual machine|Parrot]].
In 2005, [[Audrey Tang]] created the [[Pugs (compiler)|Pugs]] project, an implementation of Perl 6 in [[Haskell]]. This acted as
In 2012, Perl 6 development was centered primarily on two compilers:<ref>{{cite web |url=http://perl6.org/compilers/features |title=Feature comparison of Perl 6 compilers |access-date=March 28, 2012 |archive-url=https://web.archive.org/web/20170811073233/https://perl6.org/compilers/features |archive-date=August 11, 2017 |url-status=dead}}</ref>
Line 227 ⟶ 221:
=== Philosophy ===
According to Wall, Perl has two slogans. The first is "There's more than one way to do it," commonly known as TMTOWTDI, (pronounced ''Tim Toady''). As proponents of this motto argue, this philosophy makes it easy to write concise statements.<ref>{{cite web |last1=Richardson |first1=Marjorie |title=Larry Wall, the Guru of Perl {{!}} Linux Journal |url=https://www.linuxjournal.com/article/3394 |website=www.linuxjournal.com |publisher=Linux Journal |access-date=16 January 2023}}</ref><ref>{{Cite journal |last=Schwartz |first=Alan |date=December 1998 |title=Tutorial: Perl, a psychologically efficient reformatting language |journal=Behavior Research Methods, Instruments, & Computers |language=en |volume=30 |issue=4 |pages=605–609 |doi=10.3758/BF03209477 |s2cid=61028367 |issn=0743-3808|doi-access=free}}</ref><ref>{{Cite journal |last=Gilbert |first=James G. R. |date=March 2002 |title=How to become a programming tadpole |url=http://www.nature.com/articles/nbt0302-221 |journal=Nature Biotechnology |language=en |volume=20 |issue=3 |pages=221 |doi=10.1038/nbt0302-221 |s2cid=38728402 |issn=1087-0156|url-access=subscription }}</ref>
The second slogan is "Easy things should be easy and hard things should be possible".<ref name="programmingperl2"/>
The design of Perl can be understood as a response to three broad trends in the computer industry: falling hardware costs, rising labor costs, and improvements in [[compiler]] technology. Many earlier computer languages, such as [[Fortran]] and C, aimed to make efficient use of expensive computer hardware. In contrast, Perl was designed so that computer programmers could write programs more quickly and easily.<ref>{{Cite web |date=February 13, 2014 |title=The Fall Of Perl, The Web's Most Promising Language |url=https://www.fastcompany.com/3026446/the-fall-of-perl-the-webs-most-promising-language |website=FastCompany |last1=Myhrvold |first1=Conor }}</ref>
Perl has many features that ease the task of the programmer at the expense of greater [[CPU]] and memory requirements. These include automatic memory management; [[dynamic typing]]; strings, lists, and hashes; regular expressions; [[type introspection|introspection]]; and an <code>eval()</code> function. Perl follows the theory of "no built-in limits",<ref name="schwartz01"/> an idea similar to the [[Zero One Infinity]] rule.
Line 255 ⟶ 249:
=== Syntax ===
Perl has been referred to as "[[wikt:line noise|line noise]]" and a "write-only language" by its critics. [[Randal L. Schwartz]] in the first edition of the book ''[[Learning Perl]]'',<ref>{{cite journal |title=Developer Update|volume=2 |journal=Dr. Dobb's Developer Update |publisher=Miller-Freeman |year=1995 |page=15}}</ref
According to the ''Perl 6 FAQ'',
In Perl, one could write the [["Hello, World!" program]] as:
Line 268 ⟶ 262:
<syntaxhighlight lang="perl">
#!/usr/bin/env perl
use strict;
use warnings;
Line 279 ⟶ 273:
while ( $remaining ) {
}
Line 286 ⟶ 280:
</syntaxhighlight>
To run the code above, store it in a file named <code>counter.pl</code>, and then execute it.
The Perl interpreter can also be used for one-off scripts on the command line. The following example (as invoked from an sh-compatible shell, such as [[Bash (Unix shell)|Bash]]) translates the string "Bob" in all files ending with .txt in the current directory to "Robert":▼
<syntaxhighlight lang="console">$ perl counter.pl 42</syntaxhighlight>
$ perl -i.bak -lp -e 's/Bob/Robert/g' *.txt▼
▲The Perl interpreter can also be used for [[One-liner program|one-off scripts]] on the [[command line]]. The following example (as invoked from an sh-compatible shell, such as [[Bash (Unix shell)|Bash]]) translates the string "Bob" in all files ending with .txt in the current directory to "Robert":
▲<syntaxhighlight lang="console">$ perl -i.bak -lp -e 's/Bob/Robert/g' *.txt</syntaxhighlight>
=== Implementation ===
Line 300 ⟶ 296:
The interpreter has an object-oriented architecture. All of the elements of the Perl language—scalars, arrays, hashes, coderefs, [[file handle]]s—are represented in the interpreter by [[struct (C programming language)|C structs]]. Operations on these structs are defined by a large collection of [[Macro (computer science)|macros]], [[typedef]]s, and functions; these constitute the Perl C [[application programming interface|API]]. The Perl API can be bewildering to the uninitiated, but its entry points follow a consistent [[naming scheme]], which provides guidance to those who use it.{{Citation needed|date=December 2020}}
The life of a Perl interpreter divides broadly into a compile phase and a run phase.<ref>A description of the Perl 5 interpreter can be found in ''Programming Perl'', 3rd Ed., chapter 18. See particularly page 467, which carefully distinguishes run phase and compile phase from [[Run time (program lifecycle phase)|run time]] and [[compile time]]. Perl "time" and "phase" are often confused.</ref> According to Aluín et al., "Perl cannot be parsed by a straight Lex/Yacc lexer/parser combination. Instead, the interpreter implements its own lexer, which coordinates with a modified GNU bison parser to resolve ambiguities in the language."<ref>{{Cite
Most of what happens in Perl's compile phase is compilation, and most of what happens in Perl's run phase is execution, but there are significant exceptions. Perl makes important use of its capability to execute Perl code during the compile phase. Perl will also delay compilation into the run phase. The terms that indicate the kind of processing that is actually occurring at any moment are ''compile time'' and ''run time''. Perl is in compile time at most points during the compile phase, but compile time may also be entered during the run phase. The compile time for code in a string argument passed to the <code>[[eval]]</code> built-in occurs during the run phase. Perl is often in run time during the compile phase and spends most of the run phase in run time. Code in <code>BEGIN</code> blocks executes at run time but in the compile phase.<!-- NOTE TO EDITORS: There is something missing in the preceding sentence -- for one thing, a comma before the conjunction. The sentence might reasonably read 'Code in BEGIN blocks executes NOT at run time, but in the compile phase,' but is that what the author intended? -->
Line 306 ⟶ 302:
At compile time, the interpreter parses Perl code into a [[Abstract syntax tree|syntax tree]]. At run time, it executes the program by [[Tree traversal|walking the tree]]. Text is parsed only once, and the syntax tree is subject to optimization before it is executed, so that execution is relatively efficient. Compile-time optimizations on the syntax tree include [[constant folding]] and context propagation, but [[peephole optimization]] is also performed.<ref>{{Cite web|title=perlguts - Introduction to the Perl API - Perldoc Browser|url=https://perldoc.perl.org/perlguts#Compile-pass-3:-peephole-optimization|access-date=2022-01-24|website=perldoc.perl.org}}</ref>
Perl has a [[Turing-complete]] [[formal grammar|grammar]] because parsing can be affected by run-time code executed during the compile phase.<ref>{{cite web |last=Schwartz |first=Randal |author-link=Randal L. Schwartz |title=On Parsing Perl |url=http://www.perlmonks.org/index.pl?node_id=44722 |access-date=2007-01-03 |archive-date=September 27, 2007 |archive-url=https://web.archive.org/web/20070927000827/http://www.perlmonks.org/index.pl?node_id=44722 |url-status=live}}</ref> The code cannot be parsed by a straight [[Lex programming tool|Lex]]/[[Yacc]] [[Lexical analysis|lexer]]/[[parser]]. To resolve ambiguities in the language the interpreter must implement its own lexer to coordinate with a modified [[GNU bison]] parser.<ref>{{Cite
It is often said that "Only perl can parse Perl",<ref>{{cite web |url=ftp://ftp.ora.com/pub/labs/tpj/tpj2.pdf |title=The Perl Journal #19/9.26 |access-date=2011-02-04 |
|url=http://blogs.perl.org/users/jeffrey_kegler/2011/10/perl-and-parsing-11-are-all-perl-programs-parseable.html
|title=Perl and Parsing 11: Are all Perl programs parseable? |last=Kegler |first=Jeffrey |date=October 7, 2011 |access-date=October 25, 2022
Line 328 ⟶ 324:
The [[CPAN|Comprehensive Perl Archive Network]] carries a complete list of supported platforms with links to the distributions available on each.<ref>{{cite web |url=http://www.cpan.org/ports/ |title=Perl Ports (Binary Distributions) |access-date=2011-01-27 |publisher=[[CPAN]] |archive-date=April 18, 2006 |archive-url=https://web.archive.org/web/20060418115903/http://www.cpan.org/ports/ |url-status=live}}</ref> CPAN is also the source for publicly available Perl modules that are not part of the core Perl distribution.{{Citation needed|date=December 2020}}
ActivePerl is a closed-source distribution from [[ActiveState]] that has regular releases that track the core Perl releases.<ref name="activestate">{{cite web |url=http://www.activestate.com/activeperl |title=ActivePerl is Perl for Windows, Mac, Linux, AIX, HP-UX & Solaris |access-date=2011-01-09 |publisher=[[ActiveState]] Software |archive-url=https://web.archive.org/web/20160331201814/http://www.activestate.com/activeperl |archive-date=March 31, 2016 |url-status=dead}}</ref> The distribution previously included the [[Perl package manager]] (PPM),<ref name="activestateppm">{{cite web |url=http://docs.activestate.com/activeperl/5.12/faq/ActivePerl-faq2.html |title=Using PPM |access-date=2011-01-09 |publisher=[[ActiveState|ActiveState Software]] |archive-date=August 27, 2010 |archive-url=https://web.archive.org/web/20100827110749/http://docs.activestate.com/activeperl/5.12/faq/ActivePerl-faq2.html |url-status=live}}</ref> a popular tool for installing, removing, upgrading, and managing the use of common Perl modules; however, this tool was discontinued as of ActivePerl 5.28.<ref>{{Cite news |last1=Crane |first1=Dana |date=July 23, 2019 |url=https://www.activestate.com/blog/goodbye-ppm-hello-state-tool/ |title=Goodbye PPM, Hello State Tool |website=Activestate.com |access-date=April 16, 2020 |archive-date=July 28, 2020 |archive-url=https://web.archive.org/web/20200728080612/https://www.activestate.com/blog/goodbye-ppm-hello-state-tool/ |url-status=live}}</ref> Included also is [[PerlScript]], a [[Windows Script Host]] (WSH) engine implementing the Perl language. [[Visual Perl]] is an ActiveState tool that adds Perl to the [[Visual Studio]] [[.NET]] development suite. A [[VBScript]]-to-Perl converter, a Perl compiler for Windows, and converters of [[AWK]] and [[sed]] to Perl have also been produced by this company and included on the ''ActiveState CD for Windows'', which includes all of their distributions plus the [[Komodo IDE]] and all but the first on the Unix–Linux–POSIX variant thereof in 2002 and afterward.
== Performance ==
Line 366 ⟶ 362:
== Community ==
Perl's culture and community has developed alongside the language itself. [[Usenet]] was the first public venue in which Perl was introduced, but over the course of its evolution, Perl's community was shaped by the growth of broadening Internet-based services including the introduction of the World Wide Web. The community that surrounds Perl was, in fact, the topic of Wall's first "State of the Onion" talk.<ref>{{cite web |url=http://grnlight.net/index.php/programming-articles/100-perl-culture |title=Perl Culture (AKA the first State of the Onion) |first=Larry |last=Wall |author-link=Larry Wall |date=2014-05-22 |access-date=May 22, 2014 |archive-date=May 22, 2014 |archive-url=https://web.archive.org/web/20140522141559/http://grnlight.net/index.php/programming-articles/100-perl-culture |url-status=
State of the Onion is the name for Wall's yearly [[keynote]]-style summaries on the progress of Perl and its community. They are characterized by his hallmark humor, employing references to Perl's culture, the wider hacker culture, Wall's linguistic background, sometimes his family life, and occasionally even his Christian background.<ref>{{cite web |title=2nd State of the Onion |last1=Wall |first1=Larry |author1-link=Larry Wall |url=http://www.wall.org/~larry/onion/onion.html |access-date=2012-10-12 |archive-date=July 17, 2012 |archive-url=https://web.archive.org/web/20120717014443/http://www.wall.org/~larry/onion/onion.html |url-status=live}} (Search for 'church')</ref> Each talk is first given at various Perl conferences and is eventually also published online.
|