in reply to Can't Reference a Sub by Variable when using Strict

Just to make the discussion complete, actually you can turn this on and off. However, I am not saying that you should turn the checking off, on the contrary, you should ALWAYS turn it on.

use warnings; my $ref = "foo"; no strict("refs"); #bad idea &$ref; #works, as strict is turned off for refs use strict("refs"); #good idea &$ref; #don't work any more sub foo { print "foo called once\n"; }

Replies are listed 'Best First'.
Re^2: Can't Reference a Sub by Variable when using Strict
by davido (Cardinal) on Oct 04, 2004 at 03:01 UTC

    you should ALWAYS turn it on.

    Don't say that, it's just not true. There are things that can best be done in ways that wouldn't pass under strict refs. But I will say that if you're going to go down that road, you should only do so fully understanding why it is that most everyone panics when they see symbolic refs. They're dangerous when used improperly, and using them properly is difficult to do... and most of the time (not always) there are better ways to do it.

    I'm willing to concede the following: "You should always turn it on, except when you shouldn't, but at those times, know what you're doing."


    Dave

      Hm... this is really about how you look at it, personally I take it religiously.

      The bottom line is that, logically, nothing requires you to turn strict off, with it on, you still can do everything, and much more safer.

        The bottom line is that, logically, nothing requires you to turn strict off, with it on, you still can do everything, and much more safer.

        You say. Try exporting symbols from one package to another like Exporter for example. AUTOLOADing is another place they have value. There *are* uses for symbolic references. With strict on *you can't do everything*. But realistically your attitude is fine. As they say, if you don't know when it is appropriate to use a symbolic reference you should not be using them.