This is an old revision of this page, as edited by Rfl (talk | contribs) at 09:41, 14 November 2004 (Web hosting advertisements). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Revision as of 09:41, 14 November 2004 by Rfl (talk | contribs) (Web hosting advertisements)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)A sample Perl program
- A sample Perl program
$message = "Hello, world! The magic number is 234542354."; print $message; $message =~ s/d+/-1/; print $message; exit 0
- The above program can be written as:
$_ = "The magic number is 150\n"; print; s/\d+/-1/; print;
- which demonstrates the idea of topic (
$_
) in Perl. Also, theexit 0
at the end is completely redundant. (See: pl:Perl) Rafał Pocztarski 07:01, 7 Aug 2004 (UTC)
- A version showing slightly more powerful regex, err, power in Perl:
$_ = "The magic number is 150\n"; print; s/ (\d+) / $1 * 2 /ex; print;
- Quite a nice example. Rafał Pocztarski 07:11, 7 Aug 2004 (UTC)
You're saying that it shows "high use of meaningful punctuation characters" ? You've never seen any REAL perl code :). What about using this (uppercase input) as an example:
while(<>) { $_=~y/a-z/A-Z/; print; }
--Taw
Even better would be a line noise winner from one of the obfuscated perl contests, if that code is public domain. :-)
But that would miss the point - we want to show real Perl code, not one that was deliberately obfuscated. --Taw
I feel this entry should shy away from obfuscated code entirely! It just helps encourage the FUD that Perl is unreadable/write only/whatever, and that's a biased opinion. I can write incredibly obfuscated Java, but no-one feels the need to be posting that on the Java page. It tarnishes the neutral tone of the entry. I'd go as far as to remove the example (it's a bit pointless anyhow, what exactly is it demonstrating? I could come up with far more interesting examples of punctuation character usage, so that can't be it).
Anway, as an aside, you do realize you can get rid of the $_ in your code?:
while(<>) { tr/a-z/A-Z/; print; }
Any books that tell you otherwise, burn 'em!
Finally there's the succinct:
print uc while (<>);
... and I'll be surprised if there's anything more readable for the same task in any other popular language, assuming you've bothered to learn at least the rudiments of Perl, that is.
-- Derek
Or better yet:
print uc while <>;
Even more clean and readable. One only has to say: uc is upper-case and the diamond is input. Great example. Rafał Pocztarski 07:04, 7 Aug 2004 (UTC)
Perl programming language?
Why is this at Perl programming language? Is there any reason for the disambiguation? Perl is just a redirect. --Eloquence 14:02 Jan 20, 2003 (UTC)
- For consistency in naming. It was decided some time ago that human languages would be suffixed "language" and computer languages would be suffixed "programming language". It's got nothing to do with disambiguation. If you are going to move all these computer language pages, make sure that you check the What links here for double redirects which you may have introduced and fix them -- Derek Ross 16:30 Jan 24, 2003 (UTC)
- I agree with the term "programming language". However, I've noticed lots of references to this class of language which call them "computer languages". I don't really agree with the latter term, since they are really just human languages used to program computers. A minor point. As to appending "programming language" to the official titles, I think that's a good idea... the single example of Java vs. Java should suffice to convince most people. 2 cents. --Patrick Corcoran
- Java is a case of disambiguation, see Misplaced Pages:Disambiguation. Perl is not. --Eloquence 16:46 Jan 24, 2003 (UTC)
- Oh, great. The naming policy changed and I never even saw the discussion, never mind took part in it. For the record I don't agree with the change and I find it annoying that it took place without any of my input. -- Derek Ross 16:42 Jan 24, 2003 (UTC)
- See the interlanguage links on Perl. Everyone else is doing the right thing already. --Eloquence 16:46 Jan 24, 2003 (UTC)
erl
See http://www.perldoc.com/perl5.8.0/pod/perlfaq1.html, under "What's the difference between Perl and perl?". erl is not and has never been an acronym. -- nknight 23:36 Mar 6, 2003 (UTC)
It would seem, though, that the Perl documentation is self-contradictory in this regard, since http://www.perldoc.com/perl5.8.0/pod/perl.html#NAME says "perl - Practical Extraction and Report Language," which is how Larry Wall is supposed to have gotten the name for the language in the first place. -- James Munroe 04:53 Aug 31, 2003 (UTC)
But if it was Practical Extraction and Report Language, the language name should be PEARL, not Perl. (Note: All caps, an `A'.) In fact, that was its original name until Larry found another language named PEARL (or Pearl). So it went to Perl, and the acronym no longer makes sense.
- Like what anon user (above) says, pearl (now perl) started off as an acronym and Larry Wall had to change the name in order to avoid clash with another language with the same name.
- The old expansion would still apply to perl as words like "and" are usually excluded from an acronym. However, Wall, the jovial person that he is, came up with the new acronym "Pathologically Eclectic Rubbish Lister" to match the new name. However I feel that these events and the link given by Nknight above should not be interpreted to mean that perl is no longer an acronym but a backronym. (refer interview with Larry Wall and the question ".. How'd you come up with that name?" http://www.linuxjournal.com/article.php?sid=3394 ) Jay 08:32, 3 Mar 2004 (UTC)
- Hi, folks; perl never was an acronym. If it was, then Larry himself is lying. Anyone who's been in perl long enough to read the FAQ knows the story, and I've never heard anyone who's actually read the story claim that it's not true. Most everyone who claims perl was originally an acronym is much further removed than those who know the truth.
- Incidentally, I corrected the famous quip, "Nothing but perl can parse Perl," from Tom Christiansen. The source on this is the FAQ. Jdavidb 15:55, 8 Mar 2004 (UTC)
- Full Ack regarding the Perl FAQ. According to it, Perl is only backronymed to Practical Extraction and Report Language.
- But (and I noticed this just in this moment) if you look at http://history.perl.org/PerlTimeline.html under 1987, the (said to be) first man page shows exactly that acronym. Perl History also talks about 18th of December 1987, release date of Perl 1.000.
- But in fact the first occurence of Perl at all was in May 1987, see http://use.perl.org/articles/03/12/15/0326207.shtml?tid=1. The therein mentioned Usenet posting can be found at http://groups.google.com/groups?selm=4628%40sdcrdcf.UUCP. The posting mentions that at that date, Perl is already 3 months old.
- I'll put the Usenet posting and the Perl History Timeline into the article as external links, so the details of what is true and what is not can be discussed before any decisions regarding the article's content are made. :-) --XTaran 23:07, 11 Mar 2004 (UTC)
Blame me for the initial-cap spelling of Perl for the language. When we were writing the first Camel book, the lowercase version of "perl" kept disappearing into the text. So I discussed with Larry, and we decided together that "perl" would represent the interpreter (and be in constant-width font as a result), and "Perl" would represent the language. And no, "PERL" was never valid. -- Randal Schwartz
Name
""Perl" was originally named "pearl", after the "pearl of great price" of Matthew 13:46"
What is the reference to this information ? Jay 14:44, 6 Mar 2004 (UTC)
- This seems to be the source, with a little bit of this thrown in for seasoning. chocolateboy 17:38, 6 Mar 2004 (UTC)
Regular Expressions with Perl Examples
"===Regular Expressions with Perl Examples===" is used in a novel way in this article. I'd have reserved that markup for section headings. - Bevo 03:20, 2 Mar 2004 (UTC)
Perl - Practical Extraction and Report Language
The manpage for Perl begins with:
NAME perl - Practical Extraction and Report Language
This article suggests that "Practical Extraction and Report Language" is deprecated and "was intended humorously". I see no evidence that this is the case. I intend to move "Practical Extraction and Report Language" into the intro and remove the presumably false statement if there are no objections.--Eloquence* 02:24, Apr 13, 2004 (UTC)
- I have strong objections, because Perl is not an acronym. The etymology of the name is very clear and would be widely known if people weren't so desirous of ignorance. All one has to do is read chapter 27 of the 3rd edition of the camel book, or google around a bit. The name of the language was originally to be "Pearl", before Larry heard of another language known as "PEARL". He removed a letter and all was well in the world. "Practical Extraction and Report Language" is a post-facto rationalization. Perl is not an acronym. -- nknight 06:53, 13 Apr 2004 (UTC)
- It doesn't matter if it is a "post-facto rationalization". We are not an etymological guide and the history of the name is only of marginal interest to most readers. If this is the way the word Perl is resolved in manuals today, then it should be prominently mentioned, not falsely claimed to be "intended humorously". I can agree to include the fact that Perl was technically not intended to be an acronym, but it is also a fact that it is today widely used as one, including by the makers of Perl.--Eloquence* 06:57, Apr 13, 2004 (UTC)
- Feel free to remove any discussion about the name itself, but I will strongly oppose any attempt to define Perl as an acronym of "Practical Extraction and Report Language", as it is simply false, as anyone that has done substantive research on the subject will tell you. -- nknight 07:06, 13 Apr 2004 (UTC)
- Etymological information is of encylopedic value, so don't remove anything of it. User:Eloquence can refer the discussions above under sections "erl" and "Name" and take inputs from it. Jay 10:32, 13 Apr 2004 (UTC)
Explanation of for/foreach Syntax
I understand that this isn't supposed to be an exhaustive explanation of Perl syntax, but for/foreach are much more flexible and useful than this suggests. At the very least, I suggest replacing the "foreach ( array )" with "foreach ( LIST )", which is more accurate. (fish_at_uc_org)
- Technically, ARRAY is more accurate. If you give a literal list, it's first copied/aliased into an array, then the array is walked. -- Randal Schwartz
- After I read your post, I immediately reverted my change (thus replacing list with array). But I'm not sure that was the right thing to do, and I don't believe you were even suggesting such a reversion. (Namely because foreach( array ) would disallow useful constructs like foreach( qw/foo bar baz/ ) and even foreach( foo() ), which Perl obviously allows.) So I've reverted my original reversion; the article now uses foreach( list ). --Diberri | Talk 06:40, Aug 23, 2004 (UTC)
- Yeah, list is more appropriate and I believe Perl does copy the contents of the list given in a foreach context. -- Sundar 10:06, Aug 23, 2004 (UTC)
- As I understand it, that part of the article is trying to explain the syntax of for, so the internals of the implementation, and the copying to a temporary array, are irrelevant. Syntactically, the target of the for is a list, not an array. Compare this with the target of pop or tie, which is syntactically an array. -- Dominus 13:44, 23 Aug 2004 (UTC)
- I agree. The array copy is an implementation detail. PhilHibbs 09:03, 24 Aug 2004 (UTC)
- It is undoubtedly an implementation detail, but nevertheless quite an important one affecting the code meaning, so the list-like syntax notwithstanding, maybe it should be stated that in fact
for
iterates over an array, not a list: @a=(1..10); for (@a) {@a=(); print} # prints only 1
- Rafał Pocztarski 18:07, 24 Aug 2004 (UTC)
- It is undoubtedly an implementation detail, but nevertheless quite an important one affecting the code meaning, so the list-like syntax notwithstanding, maybe it should be stated that in fact
- Saying that perl expects a LIST at that point doesn't imply that an array is being flattened into a LIST, does it? An array is still a LIST. (fish_at_uc_org)
- You make a good point, but I'm not sure this article (or any article on a programming language) should get into such minutiae. Since arrays are lists, but not vice versa, foreach( list ) should be used because 1) it's correct, even considering minute details, and 2) it's simpler than saying foreach( array ) and then having to qualify it. --Diberri | Talk 00:55, Sep 15, 2004 (UTC)
Sample code formatting
Regarding Ævar Arnfjörð Bjarmason's changes to the code formatting (using <tt> instead of <pre>), I think I prefer the look that the stylesheet imparts to <pre> blocks. --Yath 23:26, 15 Aug 2004 (UTC)
Logo sugegstion
Programming Republic Of Perl
perl.com logo
<div style="float:right;width:97px;text-align:center"> ] <br> <small> </small> </div>
Would the <div> code above be acceptable as an alternative to the bare image link, given the copyright restriction on the image (which I have expressed concerns about on the image talk page)?
- No need for explicit DIV, just use the WikiImage code (as I have done). HTH HAND --Phil | Talk 13:24, Aug 20, 2004 (UTC)
- OK, I was trying to avoid the frame, but I guess that's in keeping with the rest of the 'pedia. In fact, I think it's better to have the frame, as it makes it clear that we are not using it as an approval stamp.PhilHibbs 13:35, 20 Aug 2004 (UTC)
Merits and demerits of Perl as a programming language
Here's some text I removed, from a section named "Merits and demerits of Perl as a programming language":
- Like all programming languages, perl does some things well, and other things, well, less than efficiently. Many programmers have come to terms with this and use a judicious mix of shell-script and perl to get around the more obvious deficiencies (date manipulation can be slow in terms of relative processing time, for example). On the upside, perl is very useful for low level file manipulation at which, in many respects, its performance is often comparable with e.g. sed.
I'm sure a section like ==Tasks for which Perl is unsuited== could be useful and informative, but the above paragraph has no redeeming qualities. Allow me to nitpick.
- a judicious mix of shell-script and perl to get around the more obvious deficiencies -- Perl replaces and exceeds sh in nearly every capacity. When perl falls short, you either switch languages or call a utility, but the instances in which that utility would be sh are vanishingly rare.
- date manipulation can be slow in terms of relative processing time, for example -- perhaps this is a rare example of when sh is better than Perl? If you can demonstrate this, I won't object to it being reinserted into the article.
- perl is very useful for low level file manipulation -- This is too vague. By "low level file manipulation", do you mean manipulating links and permissions, or something even lower? Perl is ok for fiddling with links and permissions, I guess, but as a strength, it's no big deal. For lower-level operations... well, you'll have to clarify if that's what you meant.
- at which, in many respects, its performance is often comparable with e.g. sed. sed? Perhaps you meant data manipulation. This is one of the foundations of Perl and is well covered elsewhere in the article.
--Yath 08:01, 14 Sep 2004 (UTC)
- I also agree. There's a lot of be said about Perl's failings and deficiencies (see Sins of Perl Revisited, for example) but I don't think this is it. -- Dominus 13:14, 14 Sep 2004 (UTC)
Web hosting advertisements
I am removing a link to a list of Web hosting advertisements ("Webmaster.org: Perl Web Hosting Plans - List of companies offering perl in their web hosting plans.") added to External links by 69.158.155.131 whose every single edit was adding links to similar lists in other articles. Rafał Pocztarski 09:41, 14 Nov 2004 (UTC)