One-line !sdrawkcab translator (for when you travel to foreign lands ;-)).
perl -e "s/(.*)\n/\n$1/ && print scalar reverse while <STDIN>"

This loops through the input from STDIN, until the user enters Ctrl-z, or ends the program with Ctrl-c.
Here is an explanation of the different parts of the program:

The first s/(.*)\n/\n$1/ simply removes the newline from the end of the input line, and places it at the start. This is so when the string is reversed, the newline will take its proper position at the end of the output line. Sure I could have used chomp, then printed out a newline with the output, but this would increase the length of the program, and the advertisement says "One line....." : not good for business :-)

The second item in the program is print scalar reverse. The reverse function reverses a list when called in list context, and a scalar when called in scalar context. Because I wanted it to reverse a single item, I had to call it in scalar context, using the scalar keyword. Note that I didn't specify any arguments, so it automatically defaulted to using $_. print then spitted out the output from reverse.

The final item is while <STDIN>. This merely loops through the input from STDIN, setting $_ each time.

)-; dnal backwards ni gniees-thgis yppaH

In reply to Yet another sdrawkcab translator by amrangaye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.