Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: What is it I don't understand about perl scoping?

by jettero (Monsignor)
on Jul 08, 2009 at 20:06 UTC ( [id://778395]=note: print w/replies, xml ) Need Help??


in reply to What is it I don't understand about perl scoping?

What you don't understand is that perl compiles that sub foo and compiles the lexical-ness of the my declarations before it executes the foo() and before it sets those lexicals below the function call.

I think it's clearer like this. It's nearly the same thing, but it doesn't have the lexical masking that yours has. That just confuses the issue.

use strict; use warnings; foo(); my ($foo, $berries) = (1,2); foo(); sub foo { print "$foo, $berries\n"; }

Here you can clearly see I'm using the foo and berries declared lexically after the function is called. The declaration happens at compile time and the initialization happens at runtime.

-Paul

Replies are listed 'Best First'.
Re^2: What is it I don't understand about perl scoping?
by brycen (Monk) on Jul 08, 2009 at 20:13 UTC
    ++ excellent answer, thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2026-02-15 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.