Keep It Simple, Stupid | |
PerlMonks |
Re^5: Extract the middle part of a listby doom (Deacon) |
on Jun 29, 2007 at 10:00 UTC ( [id://624071]=note: print w/replies, xml ) | Need Help?? |
BTW, am I right in believing that the logic is up/back for outer sub-blocks ie greps, but fwd/down for sub-block contents? Yes, essentially. Really perl reads everything from left-to-right, but it does "assignment" from right to left. With the usual formatting, it feels like the logical lines (seperated by semicolons) are being processed from top-to-bottom, but when you've got long chains of map/grep operations, it's traditional to put in line breaks, which makes it look like it's reading bottom-to-top, though really it's doing multiple assignments at once, going from right-to-left. Does that make sense? A "Schwartzian" operation (sorting on a computed field), might seem like it's working bottom-to-top:
But really it's doing assignment from right-to-left:
It does seem jarring to encounter a multi-line block in something like a grep, because it feels like the order of processing is jumping around: the whole program goes top-to-bottom, assignment in each logical line goes right-to-left, but then if you slip in a block with multiple lines, the top-to-bottom flow takes over again.
In Section
Seekers of Perl Wisdom
|
|