I was playing around with some sillyness ensuing the usual Emacs vs. vi arguments, and while I've not seen any other use than this silly problem, I'm stumped how inelegant my solution to the problem is.

The idea is to print the sentences

Why do we have to hide from the police, daddy ? Because they use emacs and we use vi, son. Why do we have to hide from the police, daddy ? Because they use vi and we use emacs, son.

The obvious "optimization" I'm aiming for is to somehow replace the double instances of Emacs and vi with something pulled from an array. The first idea I came up with, was the following :

print "Why do we have to hide from the police, daddy ?\n Because they + use $_->[0] and we use $_->[1], son.\n" for ($_,reverse @$_) for (["emacs","vi"])

This idea was a nice idea, but it dosen't work, as Perl does not want double for statements within one statement. It would also raise the question which of the postfix for statements would be evaluated first.

My second solution then was

do { foreach ($_, [reverse @$_]){print "Why do we have to hide from the p +olice, daddy ?\n Because they use $_->[0] and we use $_->[1], son.\n +"} } for (["emacs","vi"])'

which is inelegant, but at least it works now. But the do strikes me as superfluous.

Any help or suggestions for my aestethic problem welcomed ;-)


In reply to for vs. reverse by Corion

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.