Content deleted Content added
GreenC bot (talk | contribs) Move 1 url. Wayback Medic 2.5 per WP:URLREQ#citeftp |
Hot basket (talk | contribs) Bump latest preview version |
||
(13 intermediate revisions by 11 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 15:
| 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|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 ⟶ 49:
[[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
== History ==
Line 145 ⟶ 138:
| 2023-11-29
|-
| {{Version|
| 2025-
|-
| {{Version|
| 2025-
|-
|
| 2025-07-03
|}▼
<!--
| {{Version|cp|5.39}}▼
|-
| 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 201 ⟶ 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 228 ⟶ 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"/>
Line 286 ⟶ 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 301 ⟶ 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 307 ⟶ 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
Line 379 ⟶ 374:
Perl poetry is the practice of writing poems that can be compiled as legal Perl code, for example the piece known as "[[Black Perl]]". Perl poetry is made possible by the large number of English words that are used in the Perl language. New poems are regularly submitted to the community at [[PerlMonks]].<ref>{{cite web |url=http://www.perlmonks.org/?node_id=1590 |title=Perl Poetry |access-date=2011-01-27 |publisher=[[PerlMonks]] |archive-date=September 27, 2007 |archive-url=https://web.archive.org/web/20070927000904/http://www.perlmonks.org/?node_id=1590 |url-status=live}}</ref>
==See also==
|