Документация
HTML CSS PHP PERL другое

Section 10.4.  Perl Poetry

 
Previous
Table of Contents
Next

10.4. Perl Poetry

Programming Perl mentions the arcane art of Perl Poetrywriting valid Perl programs that, shall we say, have greater literary than pragmatic value.

One-Liners

Somewhat related to golf is the culture of one-liners; seeing how much you can get done in a single line of Perl, sometimes in unexpected ways. For instance, everyone knows that you can count the number of lines in a file using the -n switch to Perl:

    perl -nle '$count++; END{print $count}'

And that you can use the $. variable instead, Perl's built-in line counter:

    perl -nle 'END{print $.}'

But only an expert one-linerer, such as Abigail, might come up with something like:[*]

    perl -wlpe '}{$_=$.'

Or how about this golf one-liner that uses a regular expression to factor a number, and hence test it for primacy?

    perl -le '(1x shift)=~/^1?$|^(11+?)\1+$/||print"Prime"'


[*] If these one-liners make too little sense, try using B::Deparse to see what Perl is really doing.

The trend for writing Perl Poetry began, of course, with Larry and the first Perl haiku:

    print STDOUT q
    Just another Perl hacker,
    unless $spring

However, Perl haiku have problemsthey require the reader to agree on certain syllabic conventions. In this case, STDOUT must be read as "standard out" instead of the more usual "studout," and the $ in $spring must be pronounced.

To avoid these kinds of confusion, Perl poems have gravitated toward the abstract, generally without a rhyme or syllabic structure. The first example of this, and the most widely known example of Perl poetry, is attributed to Larry: the Black Perl poem that can be found in Programming Perl.

As noted there, the undisputed master of Perl poetry is Sharon Hopkins, whose listen, reverse, rush, and shopping poems have received widespread critical acclaim and publication in major periodicals.

The practice of Perl poetry has passed its azimuth and is now in decline, save for the occasional Perl poetry contest and entries on the Poetry page of perlmonks.org. This is partially due to lack of interest and partially due to a concerted effort by Larry to ensure that Black Perl does not run on modern versions of Perl. That said, I wish to humbly offer a personal example, inspired by the great masterwork of Proust, À la Récherche du Temps Perdu:

    for(long => time) {$early && $self->went($bed);}
    rand time && do {
        while ($candle--) {
            (time => $eyes->shut(  )) < (time => print "Falling asleep!")
        }
    };

    Previous
    Table of Contents
    Next
    © 2000- NIV