Content deleted Content added
Hot basket (talk | contribs) Bump stable release version, update version history table, fix/update major release dates, small clean up around |
Hot basket (talk | contribs) Bump latest preview version |
||
(8 intermediate revisions by 7 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
Line 17:
| latest release version = 5.42.0<ref>{{cite web |url=https://www.nntp.perl.org/group/perl.perl5.porters/2025/07/msg270067.html |title=Perl v5.42.0 is now available! |access-date=2025-07-13 |publisher=www.nntp.perl.org}}</ref>
| latest release date = {{Start date and age|2025|07|03|df=yes}}
| latest preview version = 5.43.
▲| latest preview version = 5.43.XX<ref>{{cite web |url= https://www.nntp.perl.org/group/perl.perl5.porters/2025/XX/msgXXXXXX.html |title=Release announcement for perl v5.43.XX |access-date=2025-XX-XX |publisher=www.nntp.perl.org}}</ref>
▲| latest preview date = {{Start date and age|2025|XX|XX|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 196 ⟶ 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 281 ⟶ 279:
print "\n";
</syntaxhighlight>
To run the code above, store it in a file named <code>counter.pl</code>, and then execute it.
<syntaxhighlight lang="console">$ perl counter.pl 42</syntaxhighlight>
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 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 book |last1=Abuin |first1=Jose M. |last2=Pichel |first2=Juan C. |last3=Pena |first3=Tomas F. |last4=Gamallo |first4=Pablo |last5=Garcia |first5=Marcos |chapter=Perldoop: Efficient execution of Perl scripts on Hadoop clusters |date=2014 |title=2014 IEEE International Conference on Big Data (Big Data)
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 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 book |last1=Abuin |first1=Jose M. |last2=Pichel |first2=Juan C. |last3=Pena |first3=Tomas F. |last4=Gamallo |first4=Pablo |last5=Garcia |first5=Marcos |chapter=Perldoop: Efficient execution of Perl scripts on Hadoop clusters |date=2014 |title=2014 IEEE International Conference on Big Data (Big Data)
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 |archive-url=https://web.archive.org/web/20200227002839/ftp://ftp.ora.com/pub/labs/tpj/tpj2.pdf |archive-date=2020-02-27 |url-status=dead |publisher=[[O'Reilly Media]] }}</ref> meaning that only the Perl interpreter (''<code>perl</code>'') can parse the Perl language (''Perl''), but even this is not, in general, true. Because the Perl interpreter can simulate a Turing machine during its compile phase, it would need to decide the [[halting problem]] in order to complete parsing in every case. It is a longstanding result that the halting problem is undecidable, and therefore not even Perl can always parse Perl. Perl makes the unusual choice of giving the user access to its full programming power in its own compile phase. The cost in terms of theoretical purity is high, but practical inconvenience seems to be rare.<ref>{{cite web
|