in reply to Is it possible to determine the eval block accumulator?

Is there any way to determine, after an eval has taken place, what the internal eval counter is in perl so I can maintain a table of eval numbers to english names so when I trap thse Apache errors I can replace (eval xxx) with something that makes a bit more sense?

Use the #line meta-comment:

eval "#line 1 foo\ndie"; print $@;

Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).

Replies are listed 'Best First'.
Re: Re: Is it possible to determine the eval block accumulator?
by BlacKat (Novice) on Feb 14, 2003 at 08:20 UTC
    This does not appear to solve my problem...

    Died at foo line 1.
    That is the result of the code snippet you provided, regardless of how many eval's have occured.

    What I am after is the *total* number of eval blocks the perl interpreter has parsed since it's been launched so that after I execute an eval block I can create a table to match the eval accumulator with a reference to the created code object.

    This way when an error occurs I can replace the obscure "(eval xxx)" references with something much more helpful for debugging.

      AFAIK the eval counter begins at 1 and increments by 1 in the order of compilation, so you should be able to find the block in question easily enough by looking at the order in which they are compiled. You might also store the code snippets in their text form inside an array starting at index 1. The real question though is why you're storing the code in raw text? Why can't you place those subroutines in another file that you require? Also, unless you have strict control over what gets submitted to you in the form of text files, you may want to run this eval'd code inside a Safe.


      "The dead do not recognize context" -- Kai, Lexx
        But the order in which the strings are compiled is of course determined at *run* time. If you see something of the form Died at (eval NNN), it means the N'th time (string) eval was called. This doesn't have much resemblence with the N'th occurance of eval in the code.

        Just try:

        perl -wle 'for (1 .. 10) {eval "die"; print $@}'

        Abigail

      Died at foo line 1. That is the result of the code snippet you provided, regardless of how many eval's have occured.

      Change foo to something that will help you debug. This does of course require eval EXPR instead of eval BLOCK.

      Juerd
      - http://juerd.nl/
      - spamcollector_perlmonks@juerd.nl (do not use).