Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: undef/defined &{$name} while "strict refs"

by Khen1950fx (Canon)
on Aug 21, 2012 at 02:38 UTC ( #988554=note: print w/ replies, xml ) Need Help??


in reply to undef/defined &{$name} while "strict refs"

You could use "the one exception to the rule":

#!/usr/bin/perl -l use autodie; use common::sense; sub walk { use strict qw/refs/; use warnings FATAL => 'syntax'; print "Walk this!"; } sub run { use strict qw/refs/; use warnings FATAL => 'syntax'; print "Run with this!"; } my $walkable = defined &{ 'walk' }; undef &{'walk'}; my $runable = \&{ 'run' }; &$runable;


Comment on Re: undef/defined &{$name} while "strict refs"
Download Code
Replies are listed 'Best First'.
Re^2: undef/defined &{$name} while "strict refs"
by anazawa (Scribe) on Aug 21, 2012 at 03:22 UTC
    Thanks to your explanation, I understand "strict refs" allows the following:
    my $runable = \&{ 'run' }; &$runable;
    Your code shows how we avoid throwing exceptions. I think, however, it's still unclear why defined/undef &{ 'run' } doesn't throw exceptions while "strict refs".

      I think, however, it's still unclear why defined/undef &{ 'run' } doesn't throw exceptions while "strict refs". ,/i>

      Have you read what strict says about refs?

      Please read it now

        The POD says we are allowed to get a reference to CODE using symbolic references while "strict refs". I think this doesn't mean we can defined or undef subroutines as well. I may be misreading the document.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (17)
As of 2015-07-29 16:43 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 (265 votes), past polls