develooper Front page | perl.perl5.porters | Postings from December 2007

Re: "strict refs" not strict enough

Thread Previous | Thread Next
From:
Ben Morrow
Date:
December 28, 2007 10:49
Subject:
Re: "strict refs" not strict enough
Message ID:
9enf45-50c.ln1@osiris.mauzo.dyndns.org

Quoth Peter@PSDT.com (Peter Scott):
> On Fri, 28 Dec 2007 03:08:33 -0500, Mark Jason Dominus wrote:
> > I would like to suggest that the real problem here is that references
> > should not be implicitly converted to strings.  If converting a
> > reference to a string were a fatal error, many or most "strict refs" errors
> > would be caught much earlier, at the place they actually occurred,
> > instead of far away.
> 
> I agree with your suggestion.  I think it should have a separate
> subpragma name rather than being convolved with 'refs'.  'refs' is
> prohibiting using strings a references.  You are prohibiting using
> references as strings.  It's only the likely intent of using a stringified
> reference as a reference later that connects the two.  I see 'refs' as
> mostly useful for slapping the hand of someone who thinks they need to use
> the contents of one variable as the name of another.

Yes. See, e.g., ~half the traffic of clpm :).

> Maybe your stricture could be "use strict 'strings'" and turned on with no
> argument like the others.

While we're dissecting 'strict': strict 'subs' ought to have been called
strict 'strings', or strict 'quotes'. Something I have often wanted, for
small scripts, is a proper no strict 'subs', that lets me call a sub
with a bareword before I've declared it (that is, unrecognized barewords
are taken to be sub calls rather than unquoted strings, except when
they're filehandles or class names). The typo-catching is much less
useful for subs than for variables, since calling an undefined sub is a
fatal error.

Ben


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About