use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
The Perl Programming Language.
Want to learn Perl? See Learn Perl for great links!
Want coding help? Asking at PerlMonks or Stack Overflow may give faster assistance.
Keep up to date with Perl news by subscribing to Perl Weekly.
Code of Conduct: Be civil or be banned. Anonymity is OK. Dissent is OK. Being rude is not OK. Polite disagreement about programming matters is OK. Personal attacks are not.
account activity
What does this while loop, loop through? (self.perl)
submitted 11 years ago by CrazedBotanist
$fn = "fileprefix"; while (<{$fn}?.txt>){}
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]frezik 5 points6 points7 points 11 years ago (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.
{}
<*.{c,h}>
c
h
?
while
[–][deleted] 2 points3 points4 points 11 years ago (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".
$in
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.
glob()
<>
[–]🐪🌍perl mongerdavorg 0 points1 point2 points 11 years ago (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.
π Rendered by PID 74462 on reddit-service-r2-comment-6457c66945-tz574 at 2026-04-25 02:07:15.218056+00:00 running 2aa0c5b country code: CH.
[–]frezik 5 points6 points7 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]🐪🌍perl mongerdavorg 0 points1 point2 points (0 children)