Perl! (19)

1 Name: !WAHa.06x36 2004-11-29 13:46 ID:YuDZAaIg [Del]

Post your favourite Perl scripts here! Let's kick it off with this one, that prints the ever-popular "just another perl hacker" text:

not exp log srand xor s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval xor print qq q q xor int
eval lc q m cos and print chr ord
for qw y abs ne open tied hex exp
ref y m xor scalar srand print qq
q q xor int eval lc qq y sqrt cos
and print chr ord for qw x printf
each return local x y or print qq
s s and eval q s undef or oct xor
time xor ref print chr int ord lc
foreach qw y hex alarm chdir kill
exec return y s gt sin sort split

2 Post deleted by user.

3 Name: Anonymous 2004-11-29 13:52 ID:ygInUEyw [Del]

@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

4 Name: hk0!0khonVgaHI 2004-11-29 22:29 ID:kP+vcXBw [Del]

>>1
That is so evil.

5 Name: hk0!0khonVgaHI 2004-11-29 23:09 ID:kP+vcXBw [Del]

$h="GABLHAAADABCDIAABIBCBIEAAMBCPMPPMOPDAGEAALBCADEAAIBCBAECAI".
"BCPAEDMIPDBAECAIBCBAECAIBCBAECIIPDBAECEIBCPAEDAIBCBAECAIBB".
"AAGAIIBAAADA";
while($h=~s/.{8}//){map{$b=($b<<4)+(ord($_)-65)}split(//,$&);
$_=unpack("b32",pack("N",$b))."\n";tr/01/ #/;print;}

6 Post deleted by user.

7 Name: !WAHa.06x36 2004-11-30 00:43 ID:2sF2hcug [Del]

That one reminds me of this, which was written by me and a friend:

$a="4 '|'\n3 (|'\n( (|/.(|W-,,'\n.(/|[-'>'\n( (|/'(|W-,''\n3 (|'\n4 '|'\n";
$a=~s/(.)(.)/print $2x((ord$1)-38)/sge;

The output probably only makes sense to old Usenetters, though.

8 Name: !WAHa.06x36 2004-11-30 00:58 ID:2sF2hcug [Del]

Also, here's a classic, which is extra fun because it's fairly easy to pick apart and understand:

perl -wle '(1 x $_) !~ /^(11+)\1+$/ && print while ++ $_'

It lists prime numbers.

9 Name: hk0!0khonVgaHI 2004-11-30 07:00 ID:oMk21ppw [Del]

I'm not getting how >>8 works. Does it have to do with the -l option... what does -l do anyway?

10 Name: Albright!LC/IWhc3yc 2004-11-30 07:06 ID:y84T0cUA [Del]

According to perl --help:

 -l[octal]       enable line ending processing, specifies line terminator

So, uh, I think it tells Perl that a program line ends when it comes to a line break, as opposed to a ;. I could be wrong...

11 Name: !WAHa.06x36 2004-11-30 13:13 ID:BZzGpAUQ [Del]

-l just adds an automatic newline after each print.

Here's a cleaner version:

while(1)
{
$n++;
if( ("1" x $n) !~ /^(11+)\1+$/ )
{
print "$n\n";
}
}

Further hints: the "x" is a string repetition operator. "a"x3 is "aaa".

12 Name: hk0!0khonVgaHI 2004-11-30 18:46 ID:3HSVphPQ [Del]

Oh. OH!
God that's retarded.
It gets the regex lib to try to see if any integer multiple (>2) of runs of '1' greater than 2 exactly fit a string of '1's as long as the number.

ARRRGH. ARRRRGH!

Hahaha.

13 Name: hk0!0khonVgaHI 2004-11-30 18:48 ID:3HSVphPQ [Del]

See I didn't understand the regex, cuz I was seeing "$/" and thinking that there was some sort of early binding going on that makes a weird regex (I only thought about that because -l in perl mentions changing the $/ and $\ variables for line endings).

Of course // binds tightly, and $/ at the end always means "end of string. I'm an idiot.

14 Name: !WAHa.06x36 2004-12-01 00:48 ID:HHExGK7w [Del]

>>12

I'm glad somebody gets it. That code makes me giggle every time I see it.

15 Name: Albright!LC/IWhc3yc 2004-12-01 02:09 ID:Cz8Uy7ig [Del]

Nerdiest thread evar.

16 Name: dmpk2k!hinhT6kz2E 2004-12-01 10:46 ID:pSlAGFqg [Del]

My favorite perl scripts are the ones that jump out of the monitor and club you in the face with obviousness. Yay for self-documenting code.

All right, maybe I'm just a bit too staid. >.>;

17 Name: !WAHa.06x36 2004-12-01 13:42 ID:ODWeu4cg [Del]

The reason I like Perl is that you can write strict, well-structured and understandable code in it, while at the same time, you can also write what pretty much amounts to humour in it. I think poetry is still out of its grasp, but overall Perl is much more like a natural language than any other programming language, since most programming languages limit their expressivity in favour of clarity. Thus, Perl does not limit creativity nearly as much as more traditional programming languages. This is both a blessing and a curse, of course, but personally, I enjoy it a lot.

18 Name: Cyb3R H4xX0r G33k 2004-12-01 20:06 ID:Heaven [Del]

> I think poetry is still out of its grasp

http://perlguy.com/contest.html

19 Name: !WAHa.06x36 2004-12-01 21:50 ID:SyYqV6Jg [Del]

But those are written in English, not Perl. If you want to (as I am trying here) consider Perl as a natural language, you'd have to express your concepts in Perl code itself, not in English words.

Still amusing, of course, but not what I was getting at.

This thread has been closed. You cannot post in this thread any longer.