So I use a file glob to match each ID value, but only half of the list elements come out as intended:
I can't figure out why the glob only works on every other iteration, or how to make it work on every iteration. This perl 5.8.7, on both macosx and freebsd.$ ls test bar_002.tst baz_003.tst faz_004.tst foo_001.tst $ cat test.list 001 002 003 004 $ perl -pale '$p=<test/*_$F[0].tst>; s/^/$p /' test.list test/foo_001.tst 001 002 test/baz_003.tst 003 004
(The made-up example is simpler than the real case: the directory actually contains thousands of files, and I have a list of 200 ids to extract path/file strings for. I know there are other ways to do this, but I'm curious about the behavior of the file glob in this case.)
UPDATE: Nevermind -- I should have looked at perldoc -f glob first:
Just changing the one-liner to start with '($p)=...' did the trick. Sorry for the spurious post.glob In list context, returns a (possibly empty) list of filename expansions on the value of EXPR such as the standard Unix she +ll /bin/csh would do. In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted.
In reply to Problem with one-liner using file globs by graff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |