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

Peeking in the source, it turns out there's a C variable that holds the count. (Not very surprising...). Here's an Inline::C program giving you access to it:
#!/usr/bin/perl use strict; use warnings; use Inline 'C'; eval 'print "Hello, world\n"'; printf "Sequence number: %d\n", gimmi (); eval 'print "Hello, earthlings\n"'; printf "Sequence number: %d\n", gimmi (); __END__ __C__ int gimmi () { return (PL_evalseq); }

That that if you run this the first time, you'll get high numbers, but that's because Inline and/or Inline::C will do some evalling as well. After that, the count starts at 2, probably also because of some evalling inside Inline and/or Inline::C.

Abigail

Replies are listed 'Best First'.
Re: Re: Is it possible to determine the eval block accumulator?
by BlacKat (Novice) on Feb 15, 2003 at 00:36 UTC
    Bingo Abigail, your answer is exactly what I was looking for! :)

    Now, to try and coerce this to work with mod_perl! :}


    For everyone else, what I am doing is parsing code snippets from multiple files, doing some regexp magic on the code snippets to replace special markup with legal perl and then creating an anonymous subroutine from the code, eval'ing it into a code reference and storing that coderef in a hash for later execution.

    Thanks to everyone for all your help and suggestions, especially Abigail for this solution! :)