Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Black Perl updated for Perl 5

by jonadab (Parson)
on Feb 21, 2003 at 15:54 UTC ( #237465=poem: print w/ replies, xml ) Need Help??

I suppose someone has probably already done this, but my attempt to find it in SuperSearch failed, so here goes. I have adapted Black Perl so that it compiles in Perl 5. It astonished me how few changes were necessary, and how little they disrupted the mood.

I didn't do this because I like Black Perl (the first time I read it, I thought, "how perverse"), but more because, having read that it would not compile in Perl 5, I felt... challenged. Though in retrospect, it wasn't much of a challenge. Still, here it is...

# Black Perl, adapted for Perl 5 by Jonadab. # Adapted from Black Perl, as seen in the Camel, # 2nd ed., p 553 BEFOREHAND: close door, each window & exit; wait until time; open spell book; study; read (spell, $scan, select); tell us; write it, print the hex while each watches, reverse length, write again; kill spiders, pop them, chop, split, kill them. unlink arms, shift, wait and listen (listening, wait). sort the flock (then, warn "the goats", kill "the sheep"); kill them, dump qualms, shift moralities, values aside, each one; die sheep; die (to, reverse the => system you accept (reject, respect)); next step, kill next sacrifice, each sacrifice, wait, redo ritual until "all the spirits are pleased"; do it ("as they say"). do it(*everyone***must***participate***in***forbidden**s*e*x*). return last victim; package body; exit crypt (time, times & "half a time") & close it. select (quickly) and warn next victim; AFTERWARDS: tell nobody. wait, wait until time; wait until next year, next decade; sleep, sleep, die yourself, die @last

So now it compiles in Perl 5 (tested with 5.6.1), but it still doesn't do anything useful. (I think I'm glad.) I suppose, having taken this step, it is inevitable that someone will also port it to Perl 6, in time. As an interesting side note, if you change $scan back to scan (as in the original) it compiles but dumps core. Maybe I should have left it that way.


sub H{$_=shift;while($_){$c=0;while(s/^2//){$c++;}s/^4//;$ v.=(' ','|','_',"\n",'\\','/')[$c]}$v}sub A{$_=shift;while ($_){$d=hex chop;for(1..4){$pl.=($d%2)?4:2;$d>>=1}}$pl}$H= "16f6da116f6db14b4b0906c4f324";print H(A($H)) # -- jonadab

Comment on Black Perl updated for Perl 5
Select or Download Code
Re: Black Perl updated for Perl 5
by Mr. Muskrat (Abbot) on Feb 21, 2003 at 15:59 UTC

    As an interesting side note, if you change $scan back to scan (as in the original) it compiles but dumps core. Maybe I should have left it that way.

    Yes, it should have been left that way. If you are going to dabble in "Black Perl" then you should expect bad things (like core dumps) to happen. ;)

Re: Black Perl updated for Perl 5
by Abigail-II (Bishop) on Feb 21, 2003 at 16:07 UTC
    You didn't use
    use strict; use warnings; use CGI;

    Abigail

Re: Black Perl updated for Perl 5
by hv (Parson) on Feb 21, 2003 at 16:12 UTC

    Very cool.

    The scan version no longer dumps core in 5.8.0, instead giving:

    Can't modify constant item in read at poem line 2, near "select)"
    but I'm not sure how to avoid it without the '$'.

    As written, though you can now lose the parens on read(), and combine:

    ... read spell, $scan, select and tell us;

    Hugo
Re: Black Perl updated for Perl 5
by mowgli (Friar) on Feb 22, 2003 at 10:29 UTC

    Sweet! Really, really sweet. Black Perl's been one of my favourite Perl poems ever since I first read it...

    --
    mowgli

Re: Black Perl updated for Perl 5
by kiz (Monk) on Sep 24, 2012 at 10:16 UTC

    Still compiles inder1 5.14

    .... but runs best as perl -X black_perl :D

    (1) inder a cross between in and under, as it "it compiles in/under perl"



    -- Ian Stuart
    A man depriving some poor village, somewhere, of a first-class idiot.

      Not without the -X flag it doesn't:

      Hash %window missing the % in argument 1 of each() at black.pl line 1. Hash %watches missing the % in argument 1 of each() at black.pl line 3 +. Array @them missing the @ in argument 1 of pop() at black.pl line 5. Array @moralities missing the @ in argument 1 of shift() at black.pl l +ine 8. Hash %aside missing the % in argument 1 of values() at black.pl line 9 +. Hash %one missing the % in argument 1 of each() at black.pl line 9. Hash %sacrifice missing the % in argument 1 of each() at black.pl line + 13. Use of "do" to call subroutines is deprecated at black.pl line 15. Use of "do" to call subroutines is deprecated at black.pl line 16.

      With -X it does compile fine though:

      # perl -X -c black.pl black.pl syntax OK

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: poem [id://237465]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-09-03 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls