Acme::BottomsUp - Write individual statements backwards
This is a fun mostly proof-of-concept module that I'm looking for comments on, especially alternative ways to code it and sample usage /possibilities (practical or otherwise)... It uses
Filter::Simple and
PPI ; source code below.
Update: 2006-08-15 uploaded to cpan as
Acme::BottomsUp
SYNOPSIS
my @arr = (1..10);
use Acme::BottomsUp;
@arr # first, start w/ numbers
grep { $_ % 2 } # then get the odd ones
map { $_**3 } # then cube each one
join ":", # and glue together
print # lastly, display result
;
print "ok";
no Acme::BottomsUp;
DESCRIPTION
This module allows you to write multi-line perl statements in reverse order so that it "reads better". For example, normally one would write the code from the SYNOPSIS as:
my @arr = (1..10);
print # lastly, display result
join ":", # and glue together
map { $_**3 } # then cube each one
grep { $_ % 2 } # then get the odd ones
@arr # first, start with numbers
;
The full source:
package Acme::BottomsUp;
use warnings;
use strict;
our $VERSION = '0.01';
use Filter::Simple;
use PPI;
FILTER {
my $doc = PPI::Document->new(\$_);
$_ = join '',
map {
my $s = $_->content;
$s =~ s/;\s*$//s;
join("\n",
reverse
split "\n",
$s
) . "\n;"
}
@{ $doc->find('PPI::Statement') };
};
1;
Considered (Marza): Split off the "offensive" talk to it's own thread or delete the posts as they have nothing to do with the topic
Unconsidered (holli): enough keep votes (Keep: 13, Edit: 4, Reap: 1)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.