The subject says it almost all, really. In particular this has come out in another thread and the present node is much a duplicate of this one, but the matter was interesting enough to be meditated separately.

Now, we all know that while applies some magic when used with angular parens to improve its use as the Perl idiomatic iterator on filehandles:

$ perl -MO=Deparse -e 'while (<>) {}' while (defined($_ = <ARGV>)) { (); } -e syntax OK
and also (but less widely known):
$ perl -MO=Deparse -e 'while (my $line=<>) {}' while (defined(my $line = <ARGV>)) { (); } -e syntax OK
Now, we also know that the intepreter does its best applying some heuristics to decide whether those parens are meant to mean (no pun intended, heh!) readline or glob. But of course one most certainly wants the former within the clause of the while loop.

The point: however, what I've just unexpectedly found out is that the same magic applies also when the angular parens have the other meaning:

$ perl -MO=Deparse -e '@a=qw/a b c/; print while <@a>' @a = ('a', 'b', 'c'); use File::Glob (); print $_ while defined($_ = glob(join($", @a))); -e syntax OK
indeed:
$ perl -le '@a=qw/a b c/; print while <@a>' a b c
It appears to work, but is much more probable not to be what one would have meant in the first place. Thus it may mask a typo or a distraction, or more simply a cargo culted use, as it seems to me in the context where I saw this popping out.

So I wonder whether this is a (perhaps unavoidable) side-effect or if it is intentional, although I doubt about the latter possibility...


In reply to C<while> magic also working with glob(): intentional or not? by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.