in reply to Using grep and glob to find directories containing file
$ mkdir dir1 dir2 dir3 $ touch dir2/foo $ perl -wE 'use Data::Dumper;print Dumper grep(glob("$_/f*"),("dir1", +"dir2", "dir3"))' $VAR1 = 'dir2';
Which is exactly what you seem to want.
Maybe your problem is actually elsewhere?
Update: I found a problem. If there's more than one match, the code skips every second dir. The reason is that glob in scalar context is stateful, and needs on extra cycle to reset. A possible fix is to evaluate the glob in list context, and check if the list has a least one element.
|
|---|