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

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.

Replies are listed 'Best First'.
Re: Re: Re: Is it possible to determine the eval block accumulator?
by djantzen (Priest) on Feb 14, 2003 at 08:51 UTC

    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

        Perhaps I'm just overtired here, but my understanding is that what the OP is talking about is loading code into subroutines *once*, not eval'ing the same string over and over again, in which case those numbers will be static.

        my $sub = eval q(sub { die }); for (1..10) { eval { $sub->() }; print "$@\n"; }

        "The dead do not recognize context" -- Kai, Lexx
Re: Re: Re: Is it possible to determine the eval block accumulator?
by Juerd (Abbot) on Feb 14, 2003 at 08:57 UTC

    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).