in reply to uninitialized value

Perl can only tell you which line, so break it up:
print $a; print $b; print $c; print $d; print $e; print $f; print $g; print $h; print $i{h};

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: uninitialized value
by Cine (Friar) on Jan 22, 2002 at 23:44 UTC
    Which wont work always :(
    try
    print eval('qq{'.$str1.'}'}; print eval('qq{'.$str2.'}'}; print eval('qq{'.$str3.'}'};
    This gives: "Use of uninitialized value in concatenation (.) at (eval 28) line 1."
    First which line is it talking about? And what value?

    T I M T O W T D I
      The solution that merlyn pointed me at is to use a #line directive like described at the very end of perlstyle. (Bug alert, in Perl 5.005 you need to have a blank line before the directive.)

      You can even wrap this up in a function with error handling like this:

      use Carp; sub my_eval { my ($pkg, $file, $line) = caller(); my $eval_str = qq(\n# line 1 "eval for file '$file' line $line"\n) . shift; if (wantarray()) { my @res = eval($eval_str); return $@ ? confess($@) : @res; } else { my $res = eval($eval_str); return $@ ? confess($@) : $res; } }
      But do be warned, your eval takes place in the scope of my_eval, and not the scope of the function you call it from. (ie You cannot access lexicals.) Unless you somewhere explicitly preprocess your code before compiling it you can't solve this generically without inlining repeated logic.

      Doing this in Perl generally requires some sophisticated hackery of the kind that gets you talked about. For the record this is exactly the kind of problem that Lisp macros are perfect for, factoring out repetitive logic in a generic way while keeping current scoping.

      Well, it works for the orginal example you gave. ;)

      (eval 28), as far as i know, means the 28th eval that has been processed. As for what value, well, you will just have to inspect that yourself. I recommend printing the the value to see what it is, just remove the eval and run it. Then, you should have a clue as to which variable is undefined.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)