20 years of line noise and here's to 20 more
December 18, 2007 11:46 AM   Subscribe

#!/usr/bin/perl
@d = localtime(time);
if ($d[4] == 11 && $d[3] == 18 ) {
 print "Happy ".($d[5]-87)."th Birthday, Perl!\n";
}
if( $ARGV[0] eq "love" || $ARGV[0] eq "hate" ) {
 print "$you can't deny its contribution to our culture\n"; 
} 

posted by [@I][:+:][@I] (135 comments total) 27 users marked this as a favorite
 
.
posted by Slack-a-gogo at 11:48 AM on December 18, 2007


Eponysterical?
posted by shakespeherian at 11:48 AM on December 18, 2007 [6 favorites]


hi bidi!
posted by dios at 11:50 AM on December 18, 2007


nerds.
posted by Stynxno at 11:50 AM on December 18, 2007


Reason for flag: "It breaks the front page."
posted by agregoli at 11:50 AM on December 18, 2007


Alright, someone's bound to complain, but I say we keep 'im. (Cute little scamp...)
posted by lodurr at 11:51 AM on December 18, 2007


We are two years late to drive in the bung. Better late than never.
posted by DU at 11:52 AM on December 18, 2007


Love love love.
posted by Wolfdog at 11:52 AM on December 18, 2007


WTF? Why is this post not titled "Perls before swine"?
posted by dersins at 11:52 AM on December 18, 2007 [11 favorites]


If this was a real Perl tribute thread, the code would be compressed to a single line.
posted by fusinski at 11:53 AM on December 18, 2007 [3 favorites]


If it is perl's first or second birthday, this produces grammatically incorrect output.
posted by jeffamaphone at 11:55 AM on December 18, 2007 [2 favorites]


Also: hate hate hate.
posted by jeffamaphone at 11:55 AM on December 18, 2007


The fact that this code will break next year really lends this that authentic Perlish quality. Well played, [@I][:+:][@I]
posted by enn at 11:56 AM on December 18, 2007 [22 favorites]


If it is perl's first or second birthday, this produces grammatically incorrect output.

You need to increase the scope of your test plan.
posted by fusinski at 11:56 AM on December 18, 2007 [2 favorites]


print "love" x 1000000;
posted by Wolfdog at 11:56 AM on December 18, 2007


Damn you, jeffamaphone.
posted by enn at 11:57 AM on December 18, 2007 [2 favorites]


I prefer Python.
posted by demiurge at 12:09 PM on December 18, 2007


Great post.
posted by Samuel Farrow at 12:14 PM on December 18, 2007


One of my favorite Perl-related bits on the intarwebs is the Perl Ad Code quiz. Basically, you read the Perl (pseudo)code to figure out what commercial slogan it represents.

Warning: really old
posted by neilkod at 12:16 PM on December 18, 2007 [1 favorite]


jaffamaphone said: If it is perl's first or second birthday, this produces grammatically incorrect output.

[@I][:+:][@I] accepts patches, not bug reports.
posted by sdodd at 12:17 PM on December 18, 2007 [3 favorites]


This really needs to be split up into MVC because that's what Rails is.
posted by bonaldi at 12:19 PM on December 18, 2007


10 print "suck it, haters."
20 goto 10
30 end

posted by Dave Faris at 12:27 PM on December 18, 2007 [5 favorites]


Line 30 is so unnecessary.
posted by fusinski at 12:29 PM on December 18, 2007 [3 favorites]


if ($d[4] == 11 && $d[3] == 18 ) {

isn't today 12/18?
posted by kickback at 12:33 PM on December 18, 2007


1. No warnings, no strict
2. No lexical scoping ("my")
3. You use || and && instead of "or" and "and". The former are lower precedence than eq and ==, so your conditionals will do wacky things
4. You never define $you
5. The spacing inside the conditional parentheses is all erratic
6. Perl 5.10 came out today. Why not install it and then use say instead of print?
posted by Plutor at 12:34 PM on December 18, 2007 [4 favorites]


If this was a real Perl tribute thread, the code would be compressed to a single line.

Yeah, but he was working from a Cookbook example that was intentionally verbose for clarity.
posted by cortex at 12:34 PM on December 18, 2007


kickback: isn't today 12/18?"

The month that localtime returns starts at zero.
posted by Plutor at 12:35 PM on December 18, 2007 [2 favorites]


isn't today 12/18?

Index from zero, bucko.
posted by cortex at 12:35 PM on December 18, 2007


I'm sure this could be acheived bettwr using a regular expression.
posted by Artw at 12:35 PM on December 18, 2007


but the day doesn't? wtf?
posted by kickback at 12:35 PM on December 18, 2007 [1 favorite]


We need a line noise flag.
posted by Crabby Appleton at 12:38 PM on December 18, 2007


but the day doesn't? wtf?

"This makes it easy to get a month name from a list" says the documentation.
posted by Plutor at 12:39 PM on December 18, 2007


Wtf indeed, kickback. Hate Perl, love this post.
posted by anomie at 12:41 PM on December 18, 2007


but the day doesn't? wtf?

You're missing out on the magic. (the logic is that much of the time you're going to use the month number to fetch a member out of an array of month names)
posted by a robot made out of meat at 12:42 PM on December 18, 2007 [1 favorite]


3. You use || and && instead of "or" and "and". The former are lower precedence than eq and ==, so your conditionals will do wacky things

In fact, both versions of the gate logic are lower precedence than eq and ==, which is why the conditionals will not do anything wacky regardless of what he ran with.

However, || and && do a short-circuit that "and" and "or" do not, so it's the better choice if you're optimizing.
posted by cortex at 12:42 PM on December 18, 2007


Ah, you're right about the precedence. Scratch #3 off my list.

But you're wrong about the short circuitry. From perlop: "As more readable alternatives to && and || when used for control flow, Perl provides and and or operators (see below). The short-circuit behavior is identical. The precedence of "and" and "or" is much lower, however, so that you can safely use them after a list operator without the need for parentheses." Having a logical or/and that doesn't short-circuit just invites non-intuitive side-effects.
posted by Plutor at 12:46 PM on December 18, 2007


Behold:

my @months = qw(jan feb mar apr may jun jul aug sep oct nov dec);
print $months[0]; # Oh, hey, that's January!


We don't have common names for days of the month beyond their numerals. Ides notwithstanding.
posted by cortex at 12:48 PM on December 18, 2007


In other news, this is still breaking the fuck out of my "Recent Activity" page. Please fix tia.
posted by dersins at 12:48 PM on December 18, 2007


Oh hey, you're right. I wonder where I got that from?
posted by cortex at 12:49 PM on December 18, 2007


> However, || and && do a short-circuit that "and" and "or" do not, so it's the better choice if you're optimizing.

And it's the semantic nuances leading to profoundly different results that build the barbed-wire fence dividing perl haters from the insane.
posted by ardgedee at 12:51 PM on December 18, 2007 [6 favorites]


I guess that is a pretty sweet feature, Plutor and Meat Robot ...considering it was written when "Never Gonna Give You Up" was still on the charts
posted by kickback at 12:52 PM on December 18, 2007



$ans[1] = "Omitted in hopes that brevity would lessen the chance of deletion.";
$ans[2] = $ans[1];
$ans[3] = "On preview.";
$ans[4] = "Agreed. I wrote a quick sed statement* to semi-fix that for v0.2";
$ans[5] = "The whitespace is exactly as I like it. TMTOWTDI";
$ans[6] = "I'm waiting for it to show up in apt";
Plutor->(@ans);

* sed 's/"$you/`whoami`."/' http://www.metafilter.com/67552/ (Yeah, I know.)
posted by [@I][:+:][@I] at 12:53 PM on December 18, 2007 [2 favorites]


I do love Perl, but I have to admit that on a big project, you either have to be incredibly strict with the structure and coding guidelines, or use something like Python.

It is fantastic for one-liners in shell scripts though.
posted by spiderskull at 12:53 PM on December 18, 2007 [1 favorite]


Hooray!
posted by eamondaly at 12:57 PM on December 18, 2007


I'm sure this could be acheived bettwr using a regular expression.

$string =~ s/bettwr/better/;
posted by neuron at 12:59 PM on December 18, 2007 [1 favorite]


Can I sed this whole affair into a conversation about Britney Spears?
posted by davejay at 1:04 PM on December 18, 2007


I went to college with Wall's son, Aaron and boy was he just like Dad. Handy to have in a math class though.
posted by Viomeda at 1:05 PM on December 18, 2007 [1 favorite]


Console.WriteLine("I never did like perl much");
posted by blue_beetle at 1:07 PM on December 18, 2007


Console.WriteLine
hush, baby. Adults are talking.
posted by boo_radley at 1:11 PM on December 18, 2007 [9 favorites]


I'm sorry, that was pretty unnecessary. I've just been working with sharepoint for the last few months, and I've developed a few tics.
posted by boo_radley at 1:12 PM on December 18, 2007


# Snip..
if (substr($d[5],length($d[5])-1) eq "1") { $suffix="st"; }
elsif (substr($d[5],length($d[5])-1) eq "2") { $suffix="nd"; }
elsif (substr($d[5],length($d[5])-1) eq "3") { $suffix="rd"; }
else { $suffix="th"; }
# Snip..
print "Happy ".($d[5]-87).$suffix." Birthday, Perl!\n";
# Snip..

posted by _aa_ at 1:12 PM on December 18, 2007 [1 favorite]


At least until 2098.

"Happy 111st Birthday, Perl".
posted by [@I][:+:][@I] at 1:15 PM on December 18, 2007


I'm pretty sure perl's days are indexed from 1 and months are indexed from 0 because that's what's in a "struct tm". It takes courage to step away from C and do it right. Like this:

In [1]: import time

In [2]: time.localtime()
Out[2]: (2007, 12, 18, 15, 15, 7, 1, 352, 0)
posted by bonecrusher at 1:15 PM on December 18, 2007 [2 favorites]


also, how is that perl 6 coming along? It's been, what? Seven years?
posted by boo_radley at 1:18 PM on December 18, 2007


I can't believe I missed out on wishing Perl a happy 11st, 12nd, and 13rd birthday.
posted by cortex at 1:22 PM on December 18, 2007 [10 favorites]


I can't believe I missed out on wishing Perl a happy 11st, 12nd, and 13rd birthday.

Can someone write a unit test first so we can get these edge cases out of the way?
posted by GuyZero at 1:33 PM on December 18, 2007


#!/usr/bin/perl -l

$_=scalar localtime;

if (/Dec 18.* (\d+)$/) {
  $a = ($1-1987);
  $b = $a % 100;
  print "Happy $a", $b > 3 ? "th" : $b == 3 ? "rd" : $b == 2 ? "nd" : "st", " Birthday, Perl!"
}

if (($_=shift) && /love/ || /hate/) {
  print "You can't deny its contribution to our culture"
}

posted by sequential at 1:39 PM on December 18, 2007


Perl. I started looking at learning Perl once, but I ended up not even bothering. And I've learned a lot of programming languages. At the time, it didn't even include multi-threading.

I'm sure it was pretty sweet in '87, but by '99 there were a lot of other alternatives. In my case, I preferred Java and didn't work on Unix that much anyway.
posted by delmoi at 1:40 PM on December 18, 2007


Wow...you can actually WORK with Sharepoint?
posted by salishsea at 1:45 PM on December 18, 2007


and didn't work on Unix that much anyway

Yeah, that's one of the key draws for me, with Perl, these days: any unix term I can get at probably has Perl and vi on it, which means I can get shit done inside of five minutes, and I rarely don't have access to a unix term.

Java's a nice language—god help me, I still think C++ is a nice language for all its warts—but so much of what I do these days is shorter one-off things that I can't be arsed to break out the big guns when Perl is standing nearby, at the ready.
posted by cortex at 1:46 PM on December 18, 2007


salishsea: yea, but I tell my momma I play piano in a whorehouse.
posted by boo_radley at 1:52 PM on December 18, 2007 [2 favorites]


It smells like Doritos in here.
posted by not_on_display at 1:59 PM on December 18, 2007 [2 favorites]


Grr. Didn't check all cases.
posted by sequential at 2:10 PM on December 18, 2007


Perl's fine for big jobs too. You just need the right tools for the job and a bit of discipline. 20 years make for a fair bit of optimization as well, which is handy if you'd actually like to scale that application some day.

PS: You really should be using the right tool for the job
posted by mock at 2:18 PM on December 18, 2007 [1 favorite]


perl -e '@d = localtime(time); ($p) = ($^X=~/^.*\/(.*)$/); $p=ucfirst($p); print "Happy ".($d[5]-87)."th Birthday, ".$p."!\n" if (($d[4] == 11) && ($d[3] == 18));'
posted by motty at 2:24 PM on December 18, 2007


use Lingua::EN::Numbers::Ordinate;
# [...]
print "Happy " . ordinate($years) . " birthday";
# [...]
# Thank you, CPAN

posted by Plutor at 2:38 PM on December 18, 2007 [1 favorite]


I love perl. Sure, it looks like random characters strung together with neither rhyme nor reason, but it also allows me to accomplish complex things really quickly--which seems like the point.
posted by sonic meat machine at 2:38 PM on December 18, 2007


\n
posted by Plutor at 2:40 PM on December 18, 2007 [1 favorite]


Yes, but can it import antigravity?
posted by signal at 2:46 PM on December 18, 2007 [1 favorite]


fuck rails
posted by arnold at 2:53 PM on December 18, 2007 [1 favorite]


wth does rails have to do with anything
posted by dmd at 2:56 PM on December 18, 2007


yes
posted by mock at 2:57 PM on December 18, 2007


I don't much like Perl as it stands, but I must admit that Perl 6 looks pretty awesome, whenever it finally comes out. It's the first top-tier language to have something very close to Lisp macros, which is pretty slick. You can manipulate the syntax of the language from within a script, (think yacc) using a built-in formal grammar system (extended regular expressions). There's also esoteric stuff like lazy lists and junctions that sound like they might be generally handy. They've also smoothed over some rough edges that made it feel so hacky before, like a more conventional OO system.

So, happy birthday. When Perl 6 finally comes out after the singularity, I'll definitely try it out.
posted by abcde at 3:03 PM on December 18, 2007


sub o{$a=shift;return $a.($a%100>=11&&$a%100<>Apologies to the author of that ordinate postfix module.  And to everyone, really.

posted by moift at 3:07 PM on December 18, 2007


Ooh, motty, I was totally guessing there was a $^X type thing, too.
posted by 31d1 at 3:07 PM on December 18, 2007


FAIL
sub o{$a=shift;return $a.($a%100>=11&&$a%100<=13?'th':$a%100%10==1?'st':$a%100%10==2?'nd':$a%100%10==3?'rd':'th')};print'Happy '.o($1*1-1987)." birthday, Perl!\n"if localtime=~/Dec\ 18.*(\d{4})/; 
posted by moift at 3:08 PM on December 18, 2007


I keep on meaning to learn Java, but then I almost always end up running into things like this (from the Ant Reference Manual):

Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes.

"Lack of any means to query or set file permissions ..."?? Double-Eww. Tee. Eff.

That's when I remember why I've never bothered to learn Java.
posted by smcdow at 3:08 PM on December 18, 2007


Can we talk about how perl6 was announced in 2000 and it's now almost 8 years later? And how irrationally angry I am about it?
posted by mrnutty at 3:23 PM on December 18, 2007 [1 favorite]


Perl exists because Larry Wall did not grok Lisp and we are all suffering for it. He nailed the whole worse-is-better philosophy, though.
posted by oncogenesis at 3:29 PM on December 18, 2007 [5 favorites]


Call MsgBox("Everyone's language is cooler than mine.", vbExclamation, "alasdair's comment")
posted by alasdair at 3:30 PM on December 18, 2007


You could always try to help. A new version of parrot was released today as well as perl 5.10.
posted by mock at 3:33 PM on December 18, 2007


Reason 1-10 to never use perl.
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
Reason 11-∞
/;{}def/#{def}def/$_={/Times-Bold exch selectfont}#/_{rmoveto}#/"{dup}#/*/!/$
;/q{exch}#/x ; {/J q #}#/.{/T q #}#{stringwidth}#{}#{}# 14 string dup dup dup
260 40 moveto 90 rotate ; %/}};$0='"\e[7m \e[0m"';@ARGV=split//,reverse
q(ThePerl). q(Journal) x 220 ; q ; 0 T putinterval exch 7 J putinterval ;
; $_= q /m$ pop T($*!$"=!$ " )pop " * true% ? $ " $!" " !! !! % !" !" !
! charpath {!"""}pop $ pop{""!}pop ! neg{!#}pop 220 ! neg _{!!}pop J false %T
charpath clip " pop 0 " moveto 6{!!}pop $_= 105{!!}pop {$ ! $ " ! #! ##}
pop{dup dup $ ! " pop pop q{"}pop 22{dup show}repeat {"}pop q 22 mul{$ "} pop
neg{!#! $ "}pop ! 8 .65 mul{$ # # $}pop ! neg{"}pop _ pop{"}pop } repeat pop
" { $ " ! ! ! $ " ! !" "#" #"!"""""! #" " # "m/;@ARGV=(@ARGV[-14..-1])x50;q}
0 "%};s/m[ou]|[-\dA-ln-z.\n_{}]|\$_=//gx;s/(.)(?{$*=''})/('$*.='.(++$#
%2?'':"$0;").'pop;')x(ord($1)-31).'$*'/gee;s/((.(\e\[.m)*|.){77})/$1\n/g;print
; sub showpage {}
Neither are original to me. They're not even new. I keep them around whenever I starting thinking that perl might be handy to use on a daily basis.
posted by eriko at 3:44 PM on December 18, 2007 [1 favorite]


Just because you can, doesn't mean you should.
posted by mrnutty at 3:47 PM on December 18, 2007


I smell an Ada programmer
posted by mock at 3:50 PM on December 18, 2007


Perl: There's more than one way to piss you off.
posted by eriko at 3:54 PM on December 18, 2007 [3 favorites]


Any language that can be used to write ugly but functional code is bad and should be avoided, clearly.
posted by cortex at 4:01 PM on December 18, 2007


eriko, if you dispense with whitespace, formatting, and good practice you can screw up any language. Ever seen obfuscated C? It's just as bad as intentionally obfuscated Perl. Some fairly standard Perl constructs are really ugly, of course, but you can also code cleanly if that's your digs.

Just don't try to use hashes of hashes.
posted by sonic meat machine at 4:21 PM on December 18, 2007


Forget English. I hear some people have used it to say things that you disagree with.
posted by Plutor at 4:22 PM on December 18, 2007 [3 favorites]


Every contact I've hard with perl has involved picking apart somebody else's buggy legacy code, filled with whatever obscure syntactical perl quirks their long departed author has locked on to, frequently mixed with huge regexs they've worked out by trial and error, which choke on unexpected edge cases. I have never seen such horrific things in any other language. So, since I don't want to get too expletivacious in a birthday celebration, I'll just let xkcd say it.
posted by Luddite at 4:25 PM on December 18, 2007


The first perl code Eriko posted there, was the second place winner from the Obfusticated Perl Contest.

any language that can actually celebrate how dense it can be written is an enemy of society.
posted by MiltonRandKalman at 4:33 PM on December 18, 2007


eriko: obfuscated Perl code is cool, but I'm more impressed by obfuscated C code, such as the following program, which apparently computes arbitrary-precision square root:
#include <stdio.h>
int l;int main(int o,char **O,
int I){char c,*D=O[1];if(o>0){
for(l=0;D[l              ];D[l
++]-=10){D   [l++]-=120;D[l]-=
110;while   (!main(0,O,l))D[l]
+=   20;   putchar((D[l]+1032)
/20   )   ;}putchar(10);}else{
c=o+     (D[I]+82)%10-(I>l/2)*
(D[I-l+I]+72)/10-9;D[I]+=I<0?0
:!(o=main(c/10,O,I-1))*((c+999
)%10-(D[I]+92)%10);}return o;}
or perhaps the following, which is a makefile, a C program, and a shell script all in one:
#include <stdio.h>
#define  true
true /*:all
CC=cc
PROG=tomx
false :
	make -f $0 $1
	exit 0
all: $(PROG)
%:%.c
	$(CC) $< -o $@
clean:
	rm $(PROG)
.PHONY: /* true clean */
	int main() {return!printf("Hello, world\n");}
(sorry for all the double-spacing; I don't know what's going on, but I'm on a Windows box with devil-carriage returns so that may be it)
posted by cobra_high_tigers at 4:41 PM on December 18, 2007


On preview, yes you guys.
posted by cobra_high_tigers at 4:42 PM on December 18, 2007


wth does rails have to do with anything

Rails probably has a built-in function to convert a number into an ordinal.
posted by smackfu at 5:43 PM on December 18, 2007


The first perl code Eriko posted there, was the second place winner from the Obfuscated Perl Contest.
any language that can actually celebrate how dense it can be written is an enemy of society.


Ya know, I actually placed, like, 2nd in my category in the 0th annual one -- it pays to pander, kids. The OPC was a clear beg from the Obfuscated C Contest -- its a targeted thing. There are times when it -is- handy to have a language that you can pack into near meaninglessness.

Of course, probably be nice if the language had functions for all those one line hacks I've been running through map{} and back but I don't think it would be as cowboy fun as it is to code. Provided me a more than decent living for more than a decade now, pulling me out of a rather high-pressure dronish job at half the salary.

I went to the first two Perl conferences and ended up in the bathroom with Larry Wall both times. Sadly, we did not have sex. Ended up getting cut off in the food line by ESR but those were different times. I don't think ESR can even be around sandwitches anymore. Were I the guy I am today I'd probably go searching out Schwartz and see if we could drink enough to beat the shit out of tchrist as he walked out of the place.

Ah, youth.
posted by Ogre Lawless at 5:52 PM on December 18, 2007 [1 favorite]


smcdow, not every OS Java supports has file permissions. That Ant script will run unchanged on Windows, OS X, Linux, Solaris, AIX, and HP-UX at least. The fact that Java discourages you from writing code that won't port means it's not the best choice for all applications. But then nothing is, right?
posted by sdodd at 6:03 PM on December 18, 2007


Leave Perl alone!
posted by telstar at 6:38 PM on December 18, 2007


Perl can be a real mess, but it can also be utterly indispensible. I can't think of another commonly available language that packs more power per syntactical unit.

Its ugly and confusing and unfriendly to the uninitiated and I can't work without it.
posted by hwestiii at 6:42 PM on December 18, 2007


Every contact I've hard with perl has involved picking apart somebody else's buggy legacy code, filled with whatever obscure syntactical perl quirks their long departed author has locked on to, frequently mixed with huge regexs they've worked out by trial and error, which choke on unexpected edge cases.

Ex. Fucking. Actly.

See, ad-hackery with perl is easy, and there's more than one way to do everything. Hell, there's a dozen ways to do everything -- and everyone picks a different one. So, someone whomps up a perl script to fix some production problem.

Time passes.

You look at it, and you cannot figure out what the fuck the thing is really doing. So, you look at the comments at the top, and call the guy who wrote it.

Who looks at it, and goes "I'm not exactly sure what I'm doing there...." Three hours later, you've basically rewritten the damn thing -- in awk and ksh, if you're "lucky," but no, you're tired, you rewrite it in perl. Three months later, neither of you can figure out what the hell it used to do or what it does now. You do the only sane thing -- drink heavily.

This is why perl is bad. You have to touch it *every day* to maintain it. TMTOWTDI is a *horrible* meme in production code. You want one way to do it -- the clearest, cleanest, easiest to read way.

Perl encourages "cleverness." Perl encourages hacks.

Hacks are bad things in production systems, and it is amazing how often cleverness will come back and bite you in the ass.
posted by eriko at 7:21 PM on December 18, 2007 [1 favorite]


the semantic nuances leading to profoundly different results

Hands up, anyone who has, or recently had, duct/gaffer tape in their home. Okay, thank you. Hands down. Now if you have a TIG welder. Yeah, that's what I thought.

Yeah, there's a language that doesn't have all that semantic complexity. It's called C. People write good code in it (some of them), in the same way that TIG workers pros make good joins (some of them). But Perl is duct tape.
posted by eritain at 7:37 PM on December 18, 2007


I'm sure I'll screw this up, and I'm sure it's overdue too, but anyway:
for((A..Z,a..z,"0".."9")){foreach$x(split//,$_){$e{$x}=scalar keys%e;}}
sub o{$o="";($s)=@_;for(n..p){$o=chr($s&255).$o;$s>>=8;}print$o;}
sub d{foreach$q(@_){if($b==4){o($s);$s=0;$b=0;}$s<<=6;$s+=$e{$q};$b++;}o($s);}
d(split(//,$$%2?"anVzdCBhbm90aGVyIHBlcmwgaGF0ZXIK":"aGFwcHkgYmlydGhkYXkgcGVybAo="));
also, my perl skills are seriously rusty, so this is nowhere near as bad as it could have been.
posted by plant at 7:42 PM on December 18, 2007


I don't have duct tape or a welder hanging around. I do have a band saw, six pots of cream cheese frosting and a bucket of liquid latex (shimmering gold) in my house.
posted by boo_radley at 7:45 PM on December 18, 2007


eriko, why not use comments?

# This does x y and z because...

If you're following good practice, perl doesn't need to be any more difficult to decipher than any other high-level language. Are there shortcuts? Sure, and for little three-line scripts that nobody is ever going to touch again, they're great. If it's something important, though, something that you will have to maintain later? Don't use shortcuts. Make comments. Hell, print the thing out and make notes on the printout if you must.

If you can't figure out what a program does later, it's not because of the language, it's because of laziness. Perl allows you to be lazy. It's a luxury. If you abuse it, that's your own fault.
posted by sonic meat machine at 7:51 PM on December 18, 2007 [1 favorite]


I heart Perl only because it allows me to perl -pi -e 's/this/that/g' * -- and that's all it ever needs to do for me, baby. Plus, you know, PIE.
posted by davejay at 8:16 PM on December 18, 2007 [1 favorite]


arg
posted by lonefrontranger at 8:20 PM on December 18, 2007


eriko, it's painfully obvious you never bothered to actually learn Perl. You're merely parroting the standard-line troll argument against it. I've seen appalling bad code in many languages, it's nothing unique to Perl. Hell, I've seen some PHP that made me cry and C that threw me into a rage - bad code is bad code.

To be fair, I think a potential key difference with Perl is that a lot of sysadmins use it, who aren't trained in CS per se. So you find a lot of copy/paste code and stream of consciousness code. However, as the default install base for other scripting languages grows (I'm lookin at you python and ruby), you'll see this trend spread. That said, if you're a half way decent programmer you should be able to figure out what's going on anyway.
posted by o0o0o at 8:31 PM on December 18, 2007 [1 favorite]


sdodd: I don't have anything against Java-the-language per se. But Java-the-implementation; that's another story.

I agree that file permissions aren't supported by every OS that Java runs on. But the design decision to make it impossible to query/manipulate file permissions via Java runtimes running on OSes that do support file permissions seems ridiculous to me.

I refuse to use a language or implementation that prevents me from writing non-portable code. Put another way: I refuse to use a language or implementation that prevents me from using facilities already provided by the operating system.

At least with Perl, one can make use of operating system facilities. On more operating systems than Java supports.
posted by smcdow at 8:32 PM on December 18, 2007


Do people actually enjoy arguing about programming? It's so bizarre.
posted by smackfu at 8:47 PM on December 18, 2007


smcdow, I'm sorry if I came off snarky there -- I posted in haste.

I'm not sure how familiar you are with Java, but it does allow you to make use of any and all operating system facilities via a mechanism called Java Native Interface (JNI). A while back I used it to access a Windows-specific API. They purposefully don't make it convenient, but it works.

As to the extent of Perl's portability vs Java: perhaps you've forgotten that Java runs on PDAs and small embedded systems, some of which don't even support spinning disks. And it runs directly on top of virtualization hypervisors such that there's no underlying OS at all. And thanks to Google, full-on Java will be running on a heck of a lot more phones in the future. Heck, you can even port a subset of your Java code to a device that uses a JVM in place of an OS.

So, Perl on more OSes than Java? I personally don't see how.
posted by sdodd at 9:32 PM on December 18, 2007


(localtime)[3]=~/1?./;print(qw(0 st nd rd)[$&]or'th');
For the suffixes, I think.

Perl is a beautiful language, with a complex culture, a rich past, certifiable geniuses working in it, and a great "literature" in CPAN.

When people tell me other languages are better, I always feel they're better the way plastic is "better" than wood. It's undeniably true, for certain tasks, but misses the point entirely.
posted by AmbroseChapel at 9:39 PM on December 18, 2007 [1 favorite]


Do people actually enjoy arguing about programming? It's so bizarre.

if ([pope shitsInWoods])
{
. . .
}
posted by secret about box at 9:41 PM on December 18, 2007


[A list of OSs perl has been ported to is here if someone wants to actually compare it with another language. Over ninety, anyway.]
posted by AmbroseChapel at 9:56 PM on December 18, 2007


Holy crap that's a lot of operating systems.
posted by sdodd at 10:29 PM on December 18, 2007


This is the kind of thread I can get behind.

The last time I set about learning Perl I gave up because the other people around me who knew "a little" Perl couldn't work out how to pass an associative array into a function by reference. That was just before I learned Python.

I continue to harbour a suspicion that Perl might actually be good for writing text processing applications, provided I don't mind throwing up in my mouth, just a little bit. So it may get learned at some point, but generally I find C++ and Java do all that I want for desktop and server applications, and Bash/awk/grep/sed/etc... are ideal for system level programming.

Oh, and in reply to criticisms of Java's lack of support for a file permissions API:
        Runtime.exec("chmod 0600 \"" + fileName + "\"");
or use the Java Native Interface. For about 99% of what you want to do on the desktop or server, Java delivers. So don't let this one failing discourage you. The above Runtime.exec() call doesn't work on Windows of course. That's an exercise for the reader.
posted by SevenPercentSolution at 11:37 PM on December 18, 2007


Do people actually enjoy arguing about programming? It's so bizarre.

if ([pope shitsInWoods])


more like:

switch(env.ShitLocation(g_thePope))
{
    case env.WOODS:

posted by panamax at 12:22 AM on December 19, 2007


The last time I set about learning Perl I gave up because the other people around me who knew "a little" Perl couldn't work out how to pass an associative array into a function by reference.

my %assoc_array_aka_hash = ();

func(\%assoc_array_aka_hash);

?

Perl rocks. Figure it out.
posted by blacklite at 2:13 AM on December 19, 2007 [1 favorite]


Luddite: "Every contact I've hard with perl has involved picking apart somebody else's buggy legacy code, filled with whatever obscure syntactical perl quirks their long departed author has locked on to, frequently mixed with huge regexs they've worked out by trial and error, which choke on unexpected edge cases. I have never seen such horrific things in any other language. So, since I don't want to get too expletivacious in a birthday celebration, I'll just let xkcd say it."

You blame this so specifically on programmers who don't know what they're doing. How can that be an argument against the language? It's an argument against untrained, unexperienced developers without peer review. Or maybe against the hiring practices wherever you work

More generally, why do people keep saying "But, but, I've seen bad code written in it!"? There's bad, buggy legacy code written in any language that's more than a year old. There is no programming construct or language family that can replace training and experience. And you can obfuscate anything. Even python and ruby for those of you holding them up as some sort of holy grail of programming languages.
posted by Plutor at 3:49 AM on December 19, 2007


I don't pretend to understand a third of what Perl is capable of, but a couple of jobs ago it was great for rapidly writing neat little and not-so-little web-apps and server tie-ins with minumum fuss that were quite extensible. It's perfectly possible to write Perl for clarity and come into someone else's code blind and know what's going on, so long as the original author isn't the kind of person whose comments are things like "#and here's the clever bit" followed by what looks like an MD5 checksum you have to incrementally tweak to blackbox its functionality until your mailserver accidentally explodes.
posted by Sparx at 4:09 AM on December 19, 2007


To be fair, I think a potential key difference with Perl is that a lot of sysadmins use it, who aren't trained in CS per se.

True. Full Disclosure -- I'm a sysadmin, not a developer. You may have hit a point here. But what I've found is that while these same sysadmins, they can write clear, easy to follow shell scripts, and well, at least legible awk and sed scripts. But perl just does something to their (ok, our) little minds.

Maybe we just can't hold our operators.
posted by eriko at 5:11 AM on December 19, 2007


SevenPercentSolution: No offense intended, but your solution to setting file permissions is laughable. Say you're writing a program which will (among other things) copy 1,048,576 files and directories, preserving their permission bits. Would you seriously suggest that this program call /bin/ls and /bin/chmod 1,048,576 times?

Who would write such a program? Me, last week. Having a direct interface to stat(2) and chmod(2) made this part of the program trivial (and fast).

And let's not even get into what happens if the node isn't a regular file. Java falls down hard on symlinks, hardlinks, Unix-domain sockets, named pipes, device nodes, etc. And this file permissions defect is just the latest (and most surprising) defect that I've discovered about Java. There are many, many others. Extrapolating (I know very little about Windows programming), I'd be willing to bet that there are also many, many facilities provided by Windows that are equally unavailable via Java-the-implementation.

Put simply, Java-the-implementation prevents a programmer use facilities already provided by the OS. And, there's no good reason for this design decision, other than the weak argument for portability. It's my prerogative if I desire to write non-portable code. The language/implementation should get out of the way and let me work. Java sacrificed a lot of capability in the name of portability. It makes it hard for those os us who never deal with portability issues to justify learning the language. (How much of the industry really deals with portability issues? With more and more S/W moving to the Web, it's a smaller and smaller fraction.)

JNI: Yes, I know it's there. In a discussion thread featuring bitching about hacks, it's hard to believe that the supreme hack that is JNI would be taken very seriously.
posted by smcdow at 5:27 AM on December 19, 2007 [1 favorite]


Portability is still a big deal even for web apps, because most companies want to host their own software within their intranet on their existing servers with their existing databases. And software sold to companies is where the money is.
posted by smackfu at 5:43 AM on December 19, 2007


gnit 1 perl 2
posted by lonemantis at 6:38 AM on December 19, 2007


And, there's no good reason for this design decision, other than the weak argument for portability.

Enforced portability may not be something you value, but the argument for it is decidedly not weak. That's like a dyed-in-the-wool functional programmer saying "there's no good reason for classes in C++, other than the weak argument for OO and templatization and all that bullshit."

Local optimization and generalized portability sit on opposite ends of a continuum along which differing needs fall.
posted by cortex at 7:04 AM on December 19, 2007


Yeah, at my last gig, between developer workstations, Dev, Alpha, QA, and Production environments, we had three versions of Solaris on two architectures, three Linux distros in five versions, two versions of Windows and Mac OS X. The server-side Java developers get to use whatever OS they want and their apps can be moved around from machine to machine freely without so much as a recompile.

But that one Solaris app written in C was a constant pain -- you couldn't even compile it without jumping through all sorts of hoops, much less test the thing. I may be wrong, but I can't help but think that had that C app been written in Perl making the exact same calls against Solaris-proprietary APIs, we would have had just as much trouble with it.

The amount of money we saved by being able to freely mix commodity Intel and Linux with high-end big-iron UNIX is not insignificant. The portability Java provides on the server side is of strategic importance.
posted by sdodd at 9:10 AM on December 19, 2007


I am amused by this thread.
posted by jeffamaphone at 9:28 AM on December 19, 2007


But, reading that USENIX presentation on LiveJournal, I certainly do respect and appreciate Perl's utility and power.
posted by sdodd at 9:30 AM on December 19, 2007


HAHA good stuff.
posted by hellslinger at 10:53 AM on December 19, 2007


You know who killed perl? O'Reilly killed perl.

perl was rocking along nicely for quite some time. Then O'Reilly gave some people a ton of money to write lots of perl books, including the 'official documentation' books. They even hired Larry for some time.

The net effect was to incent the people pragmatically in charge of Perl's development to be desperately hidebound and conservative, because any change would cause their books and their documentation to be out of date. This was bad, because Perl desperately needed fixes and updates and solutions to, e.g., the object model.

Perhaps noticing this or perhaps not, Larry then went ahead and split perl5-porters, the one place where interesting things were being discussed, into like 80 little subgroups. What little culture that was allowed to flourish quickly evaporated. No matter how many charming little yearly explanations of what he wanted out of perl6, Larry couldn't get those people back. No culture, no hackers. No hackers, no source code. I still have no idea why he couldn't do it himself, but apparently it's too big a job. So all that was left were the book authors, who were descriptive rather than creative, and still incented not to permit change.

Disclaimer: I created and ran the obfuscated perl contest.
posted by felix at 1:00 PM on December 19, 2007 [1 favorite]


Now that I think about it, you're right. Every language about which books have been written has inevitably failed.
posted by Plutor at 2:53 PM on December 19, 2007 [4 favorites]


felix: The net effect was to incent the people pragmatically in charge of Perl's development to be desperately hidebound and conservative, because any change would cause their books and their documentation to be out of date.

Well, that may be true, but evidence from the textbook publishing industry would suggest otherwise.

What textbook publishers know is that they can publish a new textbook every one to two years on every major subject, and everyone who takes that class it's used for will have to buy the new edition instead of getting it used.

The parallel in language references is that yard sales and thrift stores are weighted down with thousands of tons of language references, cookbooks, etc. If the language foundation is stable, you can pay $.50 for those instead of $50 for O'Reilly's. Similarly, you have little need of their online libraries if the foundation is stable (assuming the argument for online references is frequent update).

So, I'd be surprised if book publishing per se was the source of any conservatism on the part of Perl thought-leaders. If they are conservative (I'll assume you know they are), I think another cause is more likely.
posted by lodurr at 3:29 AM on December 20, 2007


Perl used to be the only game in town. A web page? modperl. But now you've got PHP or Rails. Scripting? perl, because shell scripting was the only other option and no one would choose that. Except now python is just as convenient and a lot of people prefer it.

The new languages are more interesting for hackers too, since everything isn't written already. If you want to write a better MP3 tag library for perl, it might take you a year to include all the features that's in MP3::Tag, and when you're done, there's a good chance no one will use it. If you write for some fancy new language, it might be the only MP3 tag library, and people will actually use your code. That's attractive.
posted by smackfu at 6:33 AM on December 20, 2007


You blame this so specifically on programmers who don't know what they're doing. How can that be an argument against the language?

Damn straight. I'm in favour of gun control as well.
posted by Luddite at 12:41 PM on December 20, 2007


lodurr, that's what you'd expect. However, there were many cases where people would kill ideas in perl5-porters specifically because it would force them to change the documentation and the book would be wrong. It amazes me too.
posted by felix at 10:40 AM on December 21, 2007


Well, then it sounds like it's not economic in the usual sense -- more in the sense of a Raymondian "bazaar". I.e., their status as arbiters of the documentation is their "wealth." Which I should have expected, I suppose.
posted by lodurr at 10:52 AM on December 21, 2007


The line between "Let's not do this because then the books will be wrong" and "Let's not do this because then all existing code that runs fine against 5.x will stop working" is pretty thin. Can you cite an example where the documentation/books are actually used as a rationale?

Also, I'd think obsoleting old books would be an argument for making language changes, since it'd sell more copies of an updated printing.
posted by Plutor at 10:58 AM on December 21, 2007


Well, yeah, as I pointed out, the textbook industry thrives on that dynamic. But Perl is part of a different culture, where "bazaar" rules might apply. It would be an interesting case in point for F/OSS advocates -- though they might not like it, since it would be an example of how "bazaar"-style interactions could stifle innovation.
posted by lodurr at 7:51 AM on December 23, 2007


« Older New iPod speaker complete with tortured fish   |   top ten stories Newer »


This thread has been archived and is closed to new comments