Why doesn't Perl file glob() work outside of a loop in scalar context?

后端 未结 4 1185
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 15:49

According to the Perl documentation on file globbing, the <*> operator or glob() function, when used in a scalar context, should iterate through the list of files matching

4条回答
  •  半阙折子戏
    2021-02-14 15:54

    (Scratching away at my rusty memory of Perl...) I think that multiple lexical instances of <*> are treated as independent invokations of glob, whereas in the while loop you are invoking the same "instance" (whatever that means).

    Imagine, for instance, if you did this:

    while (<*>) { ... }
    ...
    while (<*>) { ... }
    

    You certainly wouldn't expect those two invocations to interfere with each other.

提交回复
热议问题