Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: subroutine ref while "strict refs"

by ikegami (Pope)
on Jul 28, 2014 at 19:43 UTC ( #1095412=note: print w/ replies, xml ) Need Help??


in reply to subroutine ref while "strict refs"

my %checkers = map {; no strict 'refs'; $_ => \&$_ } qw( check_char check_time check_date check_numeric );
or
my %checkers = map { $_ => \&$_ } # \&$_ is except from strict refs. qw( check_char check_time check_date check_numeric );
Then in the loop,
my $checker_name = $rec_layout_hash{$fields[0]}{$i}{"sub_routine"}; my $checker = $checkers{$checker_name} or die("Unrecognized checker $checker_name\n"); $checker->($value1, $value2);


Comment on Re: subroutine ref while "strict refs"
Select or Download Code
Re^2: subroutine ref while "strict refs"
by Anonymous Monk on Jul 28, 2014 at 20:22 UTC
    \&$_ is except from strict refs

    Very good point, although I think (?) that's just a specific case of the more general exemption my $x = "foo"; my $y = \&$x; &$y; or my $y = \&{"foo"}; &$y;

      I didn't mean to be exclusionary. \&{EXPR} as a whole is exempt, including the \&$NAME shorthand. CONST->() is also exempt.

      For example, (\&$name)->() is the same as $name->(), but it bypasses the symbolic reference check requested by using strict.

Re^2: subroutine ref while "strict refs"
by viffer (Sexton) on Jul 29, 2014 at 03:32 UTC
    Thanks to everyone for your input, a number of options to consider. Much appreciated.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-12-27 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls