Acme-BottomsUp
view release on metacpan or search on metacpan
Acme-BottomsUp
Write individual statements backwards
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;
INSTALLATION
To install this module, run the following commands:
lib/Acme/BottomsUp.pm view on Meta::CPAN
use strict;
our $VERSION = '0.02';
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') };
};
lib/Acme/BottomsUp.pm view on Meta::CPAN
Version 0.02
=head1 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;
=head1 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
;
=head1 PREREQUISITES
=over 4
=item *
t/odd_cubes.t view on Meta::CPAN
use warnings;
use Test::More tests=> 2;
my @arr = (1..10);
my $answer = '1:27:125:343:729';
my $x;
use Acme::BottomsUp;
@arr # start w/ numbers
grep { $_ % 2 } # get the odd ones
map { $_**3 } # cube each one
join ":", # glue together
$x = # store result
;
is($x, $answer);
no Acme::BottomsUp;
$x = join ":",
map { $_**3 }
grep { $_ % 2 }
@arr
;
is($x, $answer);
( run in 0.822 second using v1.01-cache-2.11-cpan-49f99fa48dc )