in reply to Re: Getting "uninitialized value" that I can't figure out...
in thread Getting "uninitialized value" that I can't figure out...

The added benefit is that the question then changes from Why does this printf produce an undef warning? to Why does gethostbyip($host) return undef?.

print is your friend...

Replies are listed 'Best First'.
Re^3: Getting "uninitialized value" that I can't figure out...
by dguntner (Novice) on Jul 23, 2007 at 20:41 UTC
    Are you saying that using print instead of printf there would have given a better idea as to what was causing the error? Yea, the problem is resolved now, but your statement has me curious. Always nice to know if something like that will help me in the future... :-)

    --Dave

      No, sorry for my ambiguity. Let me be pedantic... The code having a problem was:
      printf("%s [ip: $ip] is alive  %.2f ms)\n", gethostbyip($host), 1000 * $duration);

      Using three seperate printf statements would have shown that $duration and $host were defined, and that gethostbyip($host) returned an undef.

      At that point, you could have asked the question Under what circumstances does gethostbyip return an undef?. Your sample code would have also been only four lines long.

      I frequently use lots of printfs (or the debugger) to narrow down a question like this.
        Oh, ok! Yea, that makes sense. Thanks for the suggestion; I'll remember that next time I'm having strange messages such as that - you're right, debugging something that way would work much better.

        --Dave