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

Re: "strict refs" not strict enough

Thread Previous | Thread Next
From:
Mark Jason Dominus
Date:
December 29, 2007 13:14
Subject:
Re: "strict refs" not strict enough
Message ID:
20071229211419.29251.qmail@plover.com

> Mark Jason Dominus wrote:
> > I have been thinking about this for a long time, and it has often
> > seemed to me that "strict refs" was not as helpful as it could be.
> 
> I agree with the problem you've outlined, in theory, but I worry about one
> thing...

I agree that it is worrisome.

> Now instead of:
> 
> 	print "Blah blah $foo blah blah";
> 
> I need:
> 
> 	printf "Blah blah %s blah blah",
> 		ref $foo ? ref2string($foo) : $foo;
> 
> Or I risk a run-time error.

You could make the same argument about dereferencing.  How about it?
You want to write

        $n_elements = @$aref;

but if you are using "strict refs" you have to put instead:

        $n_elements = ref($aref) ? @$aref : .... ;

or you risk a run-time error.  

But presumably you don't do this, and you don't let it prevent you
from using "strict refs" either.  So why are the two situations
different?  (This is not a rhetorical question.)


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