Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Closures clarification

by shmem (Chancellor)
on Dec 04, 2007 at 13:33 UTC ( #654783=note: print w/replies, xml ) Need Help??

in reply to Closures clarification

why this is not a closure though ?

Because it is just a bare block. See perlsub and perlref, section Making References and the example there for how closures work.

in my eyes my $a is visible outside the {} many thanks

Outside the scope of that bare block, you see the global $a, which is special (see sort). How can you tell that it is the same as the $a declared with my inside the block? The inner is just declared and not used in any way. Here's how to check that:

use warnings; use strict; $a=1; { my $a = 5; } print $a; __END__ 1

One last thing - be sure that your example code actually compiles. Your first example doesn't, and in your second example there's a ';' missing at the end of $a=1


_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-02-27 21:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found