> On Sun, Jun 6, 2010 at 08:19, Shawn H Corey <shawnhco...@gmail.com> wrote:
>> On 10-06-05 03:26 PM, Bryan Harris wrote:
>>> 
>>> [console]
>>> $ perl -e 'use warnings; $c=undef; printf("%s", $c->[0]{dog})'
>>> Use of uninitialized value in printf at -e line 1.
>>> [/console]
>>> 
>>> Anything that can help me here?  I wish it'd say:
>>> 
>>>   Use of uninitialized value $c->[0]{dog} in printf at -e line 1.
>>> 
>>> ... but it doesn't.
>> 
>> I wish it would say:
>> 
>> Not an ARRAY reference in printf at -e line 1.
> snip
> 
> But that is not the problem; autovivification will create the references:
> 
> perl -MData::Dumper -le '$c->[0]{a}; print Dumper $c'
> 
> The problem is that $c->[0]{dog} doesn't have anything in it (i.e. it
> is undef).  The error message should theoretically be able to find
> that the problem is linked to the variable $c like this one does:
> 
> perl -we 'my $c; printf "%s", $c'
> 
> but the problem with that is it is only indirectly linked with $c and
> you could have a situation like
> 
> perl -wle '$c={a=>1,b=>2}; print $c->{z}, $c->{b};'
> 
> If the warning said the problem was with $c, you wouldn't know which
> expresion was undef, and it might lead you to think that the problem
> was with $c, not the fact that you used "z" instead of "a" as a key.
> You could make the error message mention the hashref, but, since data
> structures can be arbitrarily deep, that could get nasty quickly.


Um, okay, but why can't it say:

  Use of uninitialized value $c->{z} in print at -e line 1.

I think I'm following the disussion, but none of it seems helpful in
addressing the root problem.  I don't want it to tell me that $c has a
problem, I want it to tell me that $c->{z} is uninitialized/undef.

How do other people deal with this?  If I have a printf with seven complex
(?, like the above) variables in it and one of them is undef, aside from
breaking them all onto different print lines and re-running the script, how
else can I figure out which one is undef?

- Bryan



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to