Corion has asked for the wisdom of the Perl Monks concerning the following question:
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 ;-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: for vs. reverse
by danger (Priest) on Mar 26, 2001 at 14:24 UTC | |
Re: for vs. reverse
by jbert (Priest) on Mar 26, 2001 at 19:41 UTC | |
by MeowChow (Vicar) on Mar 27, 2001 at 01:26 UTC | |
Re: for vs. reverse
by jlp (Friar) on Mar 26, 2001 at 14:17 UTC | |
Re: for vs. reverse
by Tyke (Pilgrim) on Mar 26, 2001 at 14:06 UTC | |
Re: for vs. reverse
by jeroenes (Priest) on Mar 26, 2001 at 14:10 UTC | |
Re (tilly) 1: for vs. reverse
by tilly (Archbishop) on Mar 27, 2001 at 03:37 UTC | |
(jcwren) Re: for vs. reverse
by jcwren (Prior) on Mar 27, 2001 at 05:21 UTC | |
by tilly (Archbishop) on Mar 27, 2001 at 05:41 UTC | |
Re: for vs. reverse
by DeaconBlues (Monk) on Mar 26, 2001 at 19:09 UTC | |
by chipmunk (Parson) on Mar 28, 2001 at 09:33 UTC | |
Re: for vs. reverse
by Fingo (Monk) on Mar 27, 2001 at 02:54 UTC |