From: Eric Wilhelm [EMAIL PROTECTED]
# from Jenda Krynicky
# on Saturday 24 November 2007 17:00:
I mean ... WHY would anyone want to write
print L(qw(a b c))-map(sub {|$_|})-join(' '), \n;
instead of
print join( ' ', map {|$_|} qw(a b c)), \n;
It is a flow from left to right rather than right to left. Each method
returns a list object, so extra map()s, grep()s, and etc just get
appended to the right -- as opposed to jumping back to the beginning of
the construct to add another transformation (and then messing with more
parenthesis.)
Are you sure you'll only ever want to add the outmost (or rightmost)
transformation? And you do not seem to have less parens.
You seem to be too tied to the do this, then do this, then do this,
then do this, ... mindset. Try to stop restricting yourself to
statements. It doesn't have to be take x, compute the sinus, compute
the square root, it can just as well be compute the square root of
the sinus of x.
Or, taking that example, join the delimited values of the list.
What I'm trying to say is, try to switch the order in your head.
Don't specify the list/array, go back to the beginning of the line,
apply one transformation, return back to the beginning of the line,
apply another transformation, return back, apply transformation to a
single string, return back, print.
I do find myself returning when I write a complex statement, but I do
not remember ever returning to the beginning of the construct. I do
tend to write () or {} and later return to fill it in, but those are
exactly your leftmost arrayobject-transforming statements.
(or in this particular case
print |, join( '| |', qw(a b c)), |\n;
)?
Well, that would be bad practice because you've repeated your separator
character and de-normalized the expression. If you just don't like the
example, feel free to write a better one.
Did I? The separator character is space, not the |. The | is a
delimiter. If there was just a separator it would look like this
print join( ',', qw(a b c)), \n;
It's the delimiter that gets repeated. How often do you need/want to
change those? Anyway which one is better depends on circumstances, if
nothing else, without the map it's quicker. And I would not say it's
more complex, just the oposite.
Jenda
P.S.: Try to reverse this:
use List::MoreUtils qw(pairwise);
print join( ', ', pairwise {$a * $b} map( floor($_), @a), map(
ceil($_), @b)), \n;
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery