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

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

  • Comment on Re^2: Can't Reference a Sub by Variable when using Strict

Replies are listed 'Best First'.
Re^3: Can't Reference a Sub by Variable when using Strict
by pg (Canon) on Oct 04, 2004 at 03:10 UTC

    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.

        Try exporting symbols from one package to another like Exporter for example.
        The code below demonstrates a very simple exporting mechanism within the confines of strict
        use strict; use warnings; use warnings::register; use Symbol 'qualify_to_ref'; sub import { my $cur = shift; my $dest = caller; for my $g (grep $cur->can($_), @_) { warnings::warnif("sub '$g' already exists in $dest") and next if $dest->can($g); my($dest, $src) = map qualify_to_ref("$_\::$g"), $dest, $cur; *$dest = *$src; } }
        One might point out that the code in Symbol doesn't use strictures, but much of this could quite easily be done within its confines, however the code would necessarily be more verbose. If someone can find code that they believe can't be done within strictures then I shall quite happily rise to the occassion :)
        HTH

        _________
        broquaint