in reply to (tye)Re: Integer detection concept
in thread Integer detection concept

No. 5 looks like a pretty cool solution to the problem. There's one thing with this code though that I can't figure out. It looks to me that you're using a closure, but it doesn't work. When I try to run this code Perl complains: Global symbol "$warn" requires explicit package name

I could only make this work by removing the outer { }. Does anyone know why this closure doesn't work?

Replies are listed 'Best First'.
(tye)Re2: Integer detection concept
by tye (Sage) on Dec 13, 2002 at 16:10 UTC

    Sorry, my bad. I fixed the code and left the original broken bit in, just commented out.

            - tye
Re^3: Integer detection concept
by dragonchild (Archbishop) on Jan 19, 2005 at 16:36 UTC
    That's because it's not a closure. Closures are subroutines that maintain the lexical state around them outside the scope of that lexical state. There's no subroutine involved.

    The reason for the extra brackets is to provide a scope for the local $^W = 1;.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Look a bit more closely. There is an anonymous sub there which gets called by the perl runtime in event of a warning.

        Which is never called outside the context of the same lexical pad. All it does is affect a variable outside of its scope. The key is that it's been assigned to local( $SIG{WARN} ) - the sub disappears when the scope goes away.

        It's kinda the opposite of a closure, if you think about it. Instead of a subroutine being called outside the scope of a lexical variable yet still affecting it, you have a variable being used outside of the lexical scope of the subroutine that affected it.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.