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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |