Jump to content

Talk:Perl

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 202.83.95.124 (talk) at 14:04, 26 September 2002 (Discussion on the example code). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

  1. A sample Perl program
       $message = "Hello, world! The magic number is 234542354.

";

       print $message;
       $message =~ s/d+/-1/;
       print $message;
       exit 0

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