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

@a=qw/a b c/; print while <@a>
That's definitely code you don't want to be using in production. You're taking a list of items, joining them with whitespace (techically, with $" which makes this even more broken), then running the glob operator on them. That expands them as filenames, but of course uses the space delimiters to separate the names. Then, the resulting list is either returned in entirity (in a list context), or doled out one-by-one in a scalar context, as you have here.

So, this is really really not the right way to walk through a list of items. It breaks when any of the following are true:

In fact, I'd say you got lucky on your choice of example!

Definitely want to steer-far-clear of code like this.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: C<while> magic also working with glob(): intentional or not?
by Util (Priest) on Sep 27, 2005 at 18:43 UTC
    ++merlyn for the detailed explanation.
    FYI, in the thread that spawned this one, we warned the code's author that the code is both wrong and scary.
Re^2: C<while> magic also working with glob(): intentional or not?
by blazar (Canon) on Sep 28, 2005 at 08:39 UTC
    That's definitely code you don't want to be using in production
    Huh! Don't misunderstand me...

    That's definitely code I don't want to be using in any case.

    More precisely, as I thought I had clearly said in, this popped out here:

    while (<@dataarray>) { my @microdata;

    Now, when I saw this I was astonished and I doubted the author's claim that "it does do the job I require", as I would have expected it to fail outright.

    OTOH I do know what is happening here but I'd like to know why it happens, that is, to express myself perhaps not extremely precisely from the technical pov, but hopefully clearly enough why "perl adds a

    defined($_ =
    in front of glob".

    The point being, I would consider it more logical either not to add anything or even to yield an error or emit a warning...