I would like to be able to specify __LINE__ and __FILE__ values that get used when I run eval(). What's the best way to do this?
Here's why I want to do this. I've been writing a Perl Debugger. Often one wants to evaluate expressions inside the debugger the way the debugged program would. So suppose the program has in it the code: basename(__FILE__). Here __FILE_ refers to the program I am debugging, not say (eval 302).
One hacky way to do this would be to try to look for occurrances of __FILE__ and __LINE__ and and replace them with scalar variables that have the values I want. I write that this is hacky because the really good regular expression probably isn't a regular expression in the classic computer science sense: a good regular expression would understand whether say __FILE__ is inside some sort of quotes or regular expression pattern. And in Perl, there is more than one way to do these.
I've also considered creating a constant or a function for these, but since __FILE__ is handled by the parser this doesn't work.
Lastly, let me mention how this is handled in Ruby. There, the eval function takes a couple of optional additional parameters which specify what to use for __FILE__ and the starting value of __LINE__.
In reply to changing __LINE__ and __FILE__ in eval by rockyb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |