in reply to How to simulate a preprocessor macro without one?

Perl5 has (unfortunately) no macro system.

You may wanna check this list of alternatives Re: Perl keyword like the C/C++ keyword 'inline'

Additionally in theory it should be possible to intercept the compilation before execution and replace the opcodes of special function calls with other code using B::Concise (and using another module to generate opcode where I can't remember the name right now¹)

Plz let me know when you implemented it 8)

Cheers Rolf

¹ it's simply B::Generate

  • Comment on Re: How to simulate a preprocessor macro without one?

Replies are listed 'Best First'.
Re^2: How to simulate a preprocessor macro without one?
by AriSoft (Sexton) on Feb 09, 2010 at 10:51 UTC

    I have studied this issue a little more. I found that practically I do not need an ordinary (source manipulating) macro function at this case. In my case I need an access to the lexical scope of the callers environment to eval string type closures as they would exist inside the callers code.

    Is there any practical method to change the lexical scope temporarily? caller() will give you some access to the callers properties but I think I need more.

    sub foo { my $name="FOO"; bar("$name"); } sub bar { my $name="BAR"; print "My name is $name"; #My name is BAR function_to_do_something_using_callers_lexical_view { print "Your name is $name"; #Your name is FOO } } foo();

    If there is no such function, as I fear, would it be "easy" or even possible to make a plugin which could install this kind of new core function to the interpreter? Or should I make my own Perl release ;-)

      > In my case I need an access to the lexical scope of the callers environment to eval string type closures as they would exist inside the callers code.

      PadWalker

      > but I think I need more.

      I think you need to rethink your questions... ;)

      Cheers Rolf

        Ok, here is my question rethinked: How could I overload the qq operator?

        With overloaded qq operator I could fully control the interpolation. For example, I could interpolate -> operators which are not available in the standard interpolation.