Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Extract the middle part of a list

by Zaxo (Archbishop)
on Jun 29, 2007 at 05:04 UTC ( [id://624033]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Extract the middle part of a list
in thread Extract the middle part of a list

As you say, your blocking is incorrect. Here's how to write that:

@t_arr = grep { $var3 = (split /[_.]/)[2]; $var3 > $var1 and $var3 <= $var2; } grep { !-d and $_ !~ /^\./ } readdir(EVT_DIR);
where I've added !-d to exclude directories. You might want to use -f instead to admit only regular files.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^4: Extract the middle part of a list
by chrism01 (Friar) on Jun 29, 2007 at 05:38 UTC
    Zaxo,
    close... it ignores curr, parent dirs fine, but still trips up over 'normal' dir. Tried it both as you said { !-d and $_ !~ /^\./ } and replace whole line with { -f }, no go.

    Chris
    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?
    Also, why 'and' not '&&'?
    This is a very educational thr (for me at least) :-)

      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:

      @result = map { ... 3 ... } sort { ... 2 ... } map { ... 1 ... };

      But really it's doing assignment from right-to-left:

      @result = map { ... 3 ... } sort { ... 2 ... } map { ... 1 ... };

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://624033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found