I hate to turn off strict. Why use strict
if you are only going to turn it off ?
I usually do this:
use strict;
sub foo { print "bar\n" }
my $func = "foo";
my $func_ref = \&{$func};
$func_ref->();
The reason this works is because the construct \&{$func}
is exempt from the rule of strict references. It is as far as I know
not documented in earlier perls, but code support for this construct has
been in for a long time. It is documented in bleadperl IIRC
The construct is often used in AUTLOAD like this:
sub AUTOLOAD {
# get params and function
# ...
my $func_ref = \&{$func};
goto &{$func_ref};
}
Autark.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|