8
while(<@thisArray>)

Does anyone know what this would do exactly? We were just having a discussion on it as it's the code is usually something like:

while(<STDIN>)
1
  • It's not supposed to do anything, as @array is not a filehandle name, it's the name of an array. Aug 6, 2012 at 18:10

3 Answers 3

10

It'll iterate through files names matched to patterns in @thisArray.

Result of perl -MO=Deparse -e '1 while(<@thisArray>)' shows that <> is converted to glob:

use File::Glob ();
'???' while defined($_ = glob(join($", @thisArray)));

From glob manual:

In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted.

Default value for $" is space, therefore multiple patterns from @thisArray will be joined into single string and then splitted back by space inside glob:

Note that glob splits its arguments on whitespace and treats each segment as separate pattern.

1
  • Thanks a lot. I was using it for a count so the count would've been way off. Aug 6, 2012 at 18:28
6

<@thisArray> works as glob(@thisArray). So it gives a list of all files matching the members of the array.

If an element of the array doesn't match a file, the element itself is returned.

5

See perlop:

If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.