As for the question of whether nesting logic helps or hurts, my experience is very strongly that it hurts my comprehension. 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. That is the same strategy with any complex control logic. If it is a single "thought" in your program, make it into line-noise. If it is central to how your program works, break it visually along the lines of how it is to be understood.
I have seen similar styles from other programmers. Including both merlyn and TheDamian. Again, I sometimes break out logic, sometimes don't. But if it is central to what I am doing, I break it out. Likewise if I start getting multiple control statements on the same line and want to reach for && as a control statement, I break it out.
As for the question of whether other languages have the piping that Perl does, I disagree. Here is a Schwartzian sort of a pipe-delimited list on the 3'rd then 5'th columns (ascending then descending) in Perl:
Here is how you do the same thing in Ruby:my @sorted = map {join, "|", @$_} sort {$a->[2] cmp $b->[2] or $a->[4] cmp $b->[4]} map {[split /\|/, $_, -1]} @my_list;
Do you see? Chaining method calls achieves exactly the same effect as Perl's pipelining does, and it even has the benefit of reading more naturally left to right! So the formatting issue is hardly unique to Perl...sorted = my_list.map { |i| [ i.split(/\|/)[2,4], i ] }.sort.map { |i| i[-1] }
In reply to Re (tilly) 3: built-ins sometimes iterating over a list, sometimes not
by tilly
in thread built-ins sometimes iterating over a list, sometimes not
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |