Perl: Difference between revisions

Content deleted Content added
Ports: "readme.txt" with no other information is the opposite of a citation, and may in fact be the most useless thing I've seen in ref tags in the history of wikipedia.
Bump latest preview version
 
(22 intermediate revisions by 17 users not shown)
Line 1:
{{Short description|Interpreted programming language first released in 1987}}
{{Other uses|Perl (disambiguation)}}
{{distinguish|PEARL (programming language)|Peril}}
{{Use mdy dates|date=September 2014}}
{{Infobox programming language
| name = Perl
| logo = Perl language perl-logo.svg
| paradigm = [[Multi-paradigm]]
| designer = [[Larry Wall]]
Line 15:
| wikibooks = Perl Programming
| released = {{Start date and age|1987|12|18}}<ref name="perltimeline"/>
| latest release version = 5.3842.30<ref>{{cite web |url=https://www.nntp.perl.org/group/perl.perl5.porters/2025/0107/msg269453msg270067.html |title=Perl 5v5.3842.30 is now available! |access-date=2025-0107-1913 |publisher=www.nntp.perl.org}}</ref> / {{Start date and age|2025|01|18|df=yes}}
| latest release version = {{Unbulleted list
| latest release date = {{Start date and age|2025|07|03|df=yes}}
 
| latest preview version = 5.4043.02<ref>{{cite web |url= https://www.nntp.perl.org/group/perl.perl5.porters/2025/0108/msg269454msg270238.html |title=Perlannouncing v5.40.1the isrelease nowof availableperl 5.43.2 |access-date=2025-0108-1922 |publisher=www.nntp.perl.org}}</ref>
| /latest preview date = {{Start date and age|2025|0108|1820|df=yes}}
 
|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}}
 
}}
 
| latest preview version=5.41.3<ref>{{cite web|url=https://www.nntp.perl.org/group/perl.perl5.porters/2024/08/msg268756.html |title=Release announcement for perl v5.41.3 |access-date=2024-08-29 |publisher=www.nntp.perl.org}}</ref> / {{Start date and age|2024|08|29|df=yes}}
 
| latest preview date=<!-- ;<br/> alpha-02 of {{nowrap|Perl 7}}<ref>{{Cite web|title=Releases · atoomic/perl|url=https://github.com/atoomic/perl/releases|access-date=2021-02-05|website=GitHub|language=en|archive-date=September 7, 2020|archive-url=https://web.archive.org/web/20200907173355/https://github.com/atoomic/perl/releases|url-status=live}}</ref><ref>{{Cite web|title=Announcing Perl 7 - nntp.perl.org|url=https://www.nntp.perl.org/group/perl.perl5.porters/2020/06/msg257565.html|last1=X|first1=Sawyer|date=June 24, 2020|quote=We intend to release 7.0.0 within a year. However, I am setting the goal of releasing it before the end of this year [2020].|access-date=2021-02-05|website=www.nntp.perl.org|archive-date=November 25, 2020|archive-url=https://web.archive.org/web/20201125230437/https://www.nntp.perl.org/group/perl.perl5.porters/2020/06/msg257565.html|url-status=live}}</ref> / {{Start date and age|2020|09|24}} -->
| 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 55 ⟶ 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 143 ⟶ 138:
| 2023-11-29
|-
| {{Version|coo|5.38}}
| 2025-0104-1813
|-
| {{Version|cco|5.40}}
| 2025-0104-1813
|-
| colspan="99" |<small>{{Version|lv|show=011111c|5.42}}</small>
| 2025-07-03
|}
<!--
| {{Version|cp|5.39}}
| 2023-04-20
|-
| {{Version|p|7.0}}
| 2024?
|-
| {{Version|cp|5.3943}}
| 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 199 ⟶ 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, and continues to act as, a test platform for the Perl 6 language (separate from the development of the actual implementation), allowing the language designers to explore. The Pugs project spawned an active Perl/Haskell cross-language community centered around the [[Libera Chat]] #raku IRC channel. Many [[functional programming]] influences were absorbed by the Perl 6 design team.<ref>{{Cite book|author1=chromatic|author1-link=chromatic (programmer)|url=https://books.google.com/books?id=JUjmsgEACAAJ|title=Modern Perl|date=2015|publisher=Pragmatic Bookshelf|isbn=978-1-68050-088-2|language=en}}</ref>
 
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 226 ⟶ 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 267 ⟶ 262:
 
<syntaxhighlight lang="perl">
#!/usr/bin/env perl
use strict;
use warnings;
Line 284 ⟶ 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>
$ perl -i.bak -lp -e 's/Bob/Robert/g' *.txt
</syntaxhighlight>
 
=== Implementation ===
Line 299 ⟶ 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) |chapter-url=https://ieeexplore.ieee.org/document/7004303 |publisher=IEEE |pages=766–771 |doi=10.1109/BigData.2014.7004303 |isbn=978-1-4799-5666-1}}</ref>
 
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 305 ⟶ 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) |chapter-url=https://ieeexplore.ieee.org/document/7004303 |publisher=IEEE |pages=766–771 |doi=10.1109/BigData.2014.7004303 |isbn=978-1-4799-5666-1}}</ref>
 
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 |publisherarchive-url=[[O'Reillyhttps://web.archive.org/web/20200227002839/ftp://ftp.ora.com/pub/labs/tpj/tpj2.pdf Media]] }}{{Dead link|archive-date=August 20242020-02-27 |boturl-status=InternetArchiveBotdead |fix-attemptedpublisher=yes[[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
|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 327 ⟶ 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.{{citation needed|date=April 2025}}
 
== Performance ==
Line 365 ⟶ 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=liveusurped}}</ref>
 
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.