perlquestion
Anonymous Monk
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'. </br>
I am using the following sample code to test:
<code>
perl -e 'use Data::Dumper; print Dumper grep(glob("$_/f*"),("dir1", "dir2", "dir3") )'
</code>
The idea being that the glob (evaluated) in scalar context, returns true if there is a file of form dirN/f* <br><br>
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. <br><br>
Any clue what is going wrong? <br>
Any suggestions for alternative approaches? <br>
14