Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Using grep and glob to find directories containing file

by Anonymous Monk
on Feb 03, 2013 at 15:09 UTC ( #1016828=note: print w/ replies, xml ) Need Help??


in reply to Re: Using grep and glob to find directories containing file
in thread Using grep and glob to find directories containing file

I thought grep will *only* return the elements of the array for which the first expression is true. Since the first expression glob("$_/f*") is only true for 'dir1', it should only return that element of the directory list (even though glob returns 3 files in that directory). The glob finds no elements in the other 2 directories, so it should be undefined which would evaluate as false.

I don't understand why the elements of glob("$_/f*") returned for the first directory entry seemingly spill over to subsequent directories in the (implicit) grep iteration.


Comment on Re^2: Using grep and glob to find directories containing file
Replies are listed 'Best First'.
Re^3: Using grep and glob to find directories containing file
by BrowserUk (Pope) on Feb 03, 2013 at 15:35 UTC
    Since the first expression glob("$_/f*") is only true for 'dir1', it should only return that element of the directory list (even though glob returns 3 files in that directory).

    You are missing the fact that grep puts the glob in a scalar context, and that makes it act as an iterator:

    In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-29 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls