Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Different behaviors between "while" and "map"

by betterworld (Deacon)
on Dec 06, 2008 at 01:42 UTC ( #728454=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Different behaviors between "while" and "map"
in thread Different behaviors between "while" and "map"

It helps to know that the loop is expanded to:

while ($_ = <SOME_FILE_HANDLE>){ ... }

This shows that <...> is nothing more than a loop condition: the loop body is executed immediately after each evaluation of the <...> operator. This is how a while loop works.


Comment on Re^3: Different behaviors between "while" and "map"
Select or Download Code
Re^4: Different behaviors between "while" and "map"
by JavaFan (Canon) on Dec 06, 2008 at 02:18 UTC
    Not for the last 12 years or so. It's expanded to
    while (defined ($_ = <SOME_FILE_HANDLE>)) { ... }

      Technically, you're both right, because

      while ($_ = <SOME_FILE_HANDLE>){ ... }
      is expanded to
      while (defined ($_ = <SOME_FILE_HANDLE>)) { ... }

      But all this is irrelevant. It's not the magical expansion of <> that causes the scalar context.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2015-07-02 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls