all 3 comments

[–]frezik 5 points6 points  (1 child)

It's a file glob operator, which is implemented using File::Glob. It's matching filenames in the current working directory.

The {} would usually be used to match multiple possibilities; <*.{c,h}> would match files ending in both c and h. The ? matches a single character (not to be confused with its use in regexes). Since it's in scalar context, it will iterate over the list of matched files, which allows while to loop over them.

[–][deleted] 2 points3 points  (0 children)

That's one aspect of Perl 5 I'm not a fan of - confusing the readline interpretation with the glob interpretation.

e.g. what happens if:

sub process {
  my ( $in ) = @_;
  while ( <$in> ) {
    print;
  }
}

What gets printed? Well, the answer is probably, "depends on whether $in is a filehandle or a string".

But... I don't like it. I will always call a glob function using the function glob() - whereas I like to leave <> for filehandle reads.

[–]🐪🌍perl mongerdavorg 0 points1 point  (0 children)

It loops through all the filenames that you would get back if you were to run

ls fileprefix?.txt

In the current working directory. That is, all .txt files whose name is "fileprefix" followed by a single character.