From your various posts in this thread:

I'm dealing with large hash structures and big input data ... [validation] is highly inefficient

Please clarify. How big and deep are your data structures? Did you try running the code I posted here on your data, and how long did it take?

Also, how are you accessing your data structure? Directly, as in printf "%s", $data->{foo}{bar}{quz}{baz}, do you copy subsections into temporary variables, do you walk the structure recursively, etc.? Again, please see SSCCE, if you could show us something that's actually representative of your code, we can give better advice.

I don't want to add any kind of extra checking code to avoid the error ... I just want to know if it's possible (without writing any specific checking code) to know the name of the variable that produces the error

I believe that Rolf showed (Update: now even including a post by the P5Porter who implemented it himself!) conclusively that in many cases, this isn't built into Perl, so the answer to your question is no. You'll have to add the checks yourself, even if you "don't want to" :-P

You could check the arguments:

use Carp qw/cluck/; sub myprintf { cluck "myprintf: undef argument(s)" if grep {!defined} @_; printf @_ } myprintf "%s-%s-%s-%s\n", 'quz', undef, 'baz', undef; __END__ myprintf: undef argument(s) at - line 4. main::myprintf("%s-%s-%s-%s\x{a}", "quz", undef, "baz", undef) cal +led at - line 7 Use of uninitialized value in printf at - line 5. Use of uninitialized value in printf at - line 5. quz--baz-

Or you could check for undefs when accessing the data:

use Carp; sub dive { my ($ref,@path) = @_; for my $i (0..$#path) { $ref = $path[$i]=~/^\[(\d+)\]$/ ? $ref->[$1] : $ref->{$path[$i]}; if (!defined $ref) { carp "undef at: ".join('', map {/^\[\d+\]$/?$_:"{$_}"} @path[0..$i]); return undef; } } return $ref; } my $data = { this => { is => { a => { deep => { structure => [ 'abc', 'def', undef ] } } } } }; printf "<%s>\n", dive($data, qw/ this is a deep structure [0] /); printf "<%s>\n", dive($data, qw/ this is a deep structure [3] /); printf "<%s>\n", dive($data, qw/ this is an example /); __END__ <abc> undef at: {this}{is}{a}{deep}{structure}[3] at - line 10. main::dive(HASH(0x9e47a4), "this", "is", "a", "deep", "structure", + "[3]") called at - line 22 Use of uninitialized value in printf at - line 22. <> undef at: {this}{is}{an} at - line 10. main::dive(HASH(0x9e47a4), "this", "is", "an", "example") called a +t - line 23 Use of uninitialized value in printf at - line 23. <>

In reply to Re: determine the variable causing the error: Use of uninitialized value by haukex
in thread determine the variable causing the error: Use of uninitialized value by ruqui

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.