What I find best for handling nested maps, greps, and sorts is to put them on separate lines, indented, to be read from bottom to top.

I do this as well, my only issue with it is where to put the listor array, on the same line as the last transformation or the line below? Also I can never quite decide how to deal with 'blockless' transforms such as sort.

@list=map {substr($_,1)} sort map {pack("CA*",length($_),$_)} @words; #or @list=map {substr($_,1)} sort map {pack("CA*",length($_),$_)} @words;
About your example from Ruby, are you allowed arbitray whitespace in between the transforms? ie could you write that as the following?
sorted = my_list.map {|i| [ i.split(/\|/)[2,4],i ]}. sort. map { |i| i[-1] }
...even has the benefit of reading more naturally left to right!

Well, while it wouldnt be difficult to write a class that supported this type of syntax, I have to say that i'm not so sure that this is more natural or not. In fact, while I dont think it would be that hard to get used to or even that it would bother me, I would actually argue that it is less natural than the perl notation, which I hasten to add does seem a little odd at first, seemingly going against the convention in a program that lines are executed in order from top to bottom. This I believe is because it is easy to think in terms of statement execution rather than what is really happening, list assignment, or function chaining.

For the sake of clarity in my argument Id like to point out that normally values move from the right to left in statements. $x=$y; for instance involves evaluating the right side and placing its value in the container on the left side. With lists we extend the idea to that of 'pouring' values from the right side into the left side.

Now when I see  @greets=map{"Hello $_!"}@names; the idea is extended so each value from the list at the right goes left, into the block and then left again into the array. And so on when we have longer chains. This also matches the way it would be written if these were all functions.

@list=map(substr($_,1),sort(map(pack("CA*",length($_),$_),@words)));
Whereas the method form would translate into a multistatement equivelent
my @tmp = map { pack("CA*",length($_),$_) } @words; my @tmp2= sort @tmp; my @list= map { substr($_,1)} @tmp2;
Which makes sense when written as multiple statements, but when written as one statement as you showed in ruby it actually seems to be unnatural. The result gets taken from the extreme right hand side and stuck in the container on the left side, which hardly seems more natural than the values flowing consistantly from right to left.

Just my $0.02 :-)

Yves / DeMerphq
--
Have you registered your Name Space?


In reply to Re: Re (tilly) 3: built-ins sometimes iterating over a list, sometimes not by demerphq
in thread built-ins sometimes iterating over a list, sometimes not by dragonchild

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.