in reply to Problem with one-liner using file globs

You are having problems with cryptocontext. glob behaves differently according to whether you use it in scalar or list context.

Your code as it stands calls glob in scalar context ($p = ...). This primes glob to set up an iterator that may return a different filename each time you call it, for filenames that match the pattern, until no more do, at which time it returns undef.

The second time you call glob with '002', you're getting the undef back that signals that nothing else matches the glob set up for '001'. By that time, the glob has been exhausted, so when you call it the next time with '003', you get something back. And so forth.

You can change your one-liner to get an array back, and just use the first element returned:

perl -pale 'print $F[0]; @p=<test/*_$F[0].tst>; s/^/$p[0] /' test.list

You may wish to iterate over @p in a loop, and deal with all that match (I cannot know if this is an issue for you or not).

Otherwise, if you only care about ever dealing with one entry, you can force a list assignment with parentheses:

perl -pale 'print $F[0]; ($p) = <test/*_$F[0].tst>; s/^/$p /' test.lis +t

update: oh bleagh, while I was testing all this out, you found the right answer anyway. So shoot me. Oh well, I hope someone finds this instructive.

• another intruder with the mooring in the heart of the Perl