Here's a cute little program that will turn a file of text upside-down (sort of):
#!/usr/bin/perl
use strict;
use warnings;
my @lines;
while(<>){
push @lines, $_;
}
while(@lines){
print flip_line(pop @lines);
}
sub flip_line
{rev_string(join '', map flip_char($_), split //, shift)}
sub rev_string
{scalar reverse shift}
sub flip_char
{$_= lc shift; tr/'ahbbmfnnjpdrvutwqgye'/'eyqgwtuvrdpjnnfmbbha'/; $_}
For example, the file
some text can be
flipped over using
this script
becomes
fdijcs siyf
buisn jano paddilt
aq uec fxaf awos
Flipping the text back over can be approximated by something like
./umop-apisdn.pl < test.txt | ./umop-apisdn.pl
This is approximate because of case changes and because the mapping function I use doesn't invert cleanly (since v and u both man to n, for example).
Note: this idea is not originally mine, I just wrote this implementation. Check out
http://poignantguide.net/ruby/chapter-7.html for the inspiration.
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.