I am trying (for example) to identify the subset of directories (in a list of directories) that contain a file beginning with the letter 'f'.
I am using the following sample code to test:
perl -e 'use Data::Dumper; print Dumper grep(glob("$_/f*"),("dir1", +"dir2", "dir3") )'
The idea being that the glob (evaluated) in scalar context, returns true if there is a file of form dirN/f*

However, somehow it is seemingly not being evaluated in scalar context to the extent that if dir1 contains N files beginning with 'f' then the first N directories are returned by grep even if none of the others contain a file beginning with 'f'. It is as if glob is not being evaluated in scalar context. Note even if I force glob to scalar using (scalar glob("$_/f*")), it still fails this way.

Any clue what is going wrong?
Any suggestions for alternative approaches?

In reply to Using grep and glob to find directories containing file by Anonymous Monk

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.