To elaborate (because this foxed me, I thought <> must have different behaviour when passed an array), as far as I can tell, the reason this appears to work is a result of:
  1. glob("pattern") returns "pattern" if no files match the pattern (this includes patterns which no metacharacters, such as 'blue');
  2. In a scalar context <pattern> is magic - it keeps state and returns each successive value of glob("pattern"). For example, create files touch tt1 tt2 tt3 and then run:
    print scalar <tt?>, "\n" for 1..3; # prints tt1, tt2 and tt3
    Note that (like the flipflop operator) each seperate instance of <pattern> appears to keep its own internal state.
    print scalar <tt?>, "\n"; print scalar <tt?>, "\n"; print scalar <tt?>, "\n"; # prints tt1, tt1, tt1
    And to drive the point home, fun with closures:
    my $s = sub { return scalar <tt?>; }; print $s->(), "\n"; print $s->(), "\n"; print $s->(), "\n"; # prints tt1, tt2, tt3
So...this will "work" provided none of the array elements is a string which both contains a glob metacharacter and matches a file as a glob. (If the array elt doesn't contain any such chars, it doesn't matter if it matches or not - you'll get back the pattern).

In reply to Re^2: process array with while loop by jbert
in thread process array with while loop by reason2006

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.