develooper Front page | perl.perl5.porters | Postings from October 2009

Re: [perl #70043] Re: [Sysadmins] Perl allows non-sensicaloperations on reference converted to an integer

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
October 27, 2009 05:47
Subject:
Re: [perl #70043] Re: [Sysadmins] Perl allows non-sensicaloperations on reference converted to an integer
Message ID:
20091027124518.GA27813@klangraum.plasmasturm.org
* George Greer <perl@greerga.m-l.org> [2009-10-27 13:15]:
> I'd perhaps use it as a "no stringify;" (like "no indirect;")

A better name might be something like `no refconv;` (which would
include preventing numeric operations on numified references).

> My favorite stringy-oops has been doing tr// on a list of mixed
> strings/refs, but that gets tracked down pretty quickly.

When working with non-trivially nested data it’s not uncommon to
get a `Can't use string ("HASH(0xdeadbeef)") as a FOO ref`
somewhere, or absurd numbers when you’re calculating some kind of
aggregate, because you accidentally accessed the wrong element
and numified a ref instead of accessing the right scalar, or
tried to deref a scalar instead of accessing the ref you wanted.

And it’s always real tedious to track down where the actual
mistake is in such cases, even when it doesn’t ultimately take
much time. You usually have to try to trace logic that winds
through recursive calls or nested loops, which is a chore whether
you debug with the debugger or with print statements.

It would be much less painful if you could at least optionally
enable a fatal error for implicit ref conversions, for debugging
purposes. That would immediately tell you the “where” half of the
problem, instead of leaving you to painstakingly hunt for it.
Throw a Carp::Always in there and you probably have most of the
data you need to figure out the “why”.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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