Outaspace has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm currently writing my own DB. How can I get the "special" vars for the last executed regexp ($&,$+,...) in my DB-Sub ??? The documentation states that they are only visible in the lexical context where the regexp is. But I think, if there is a way to do it (Perl is great), someone here must know the answer. Andre
  • Comment on Getting Special Perl Variables for last Regexp from Debugger

Replies are listed 'Best First'.
Re: Getting Special Perl Variables for last Regexp from Debugger
by Moron (Curate) on Nov 28, 2005 at 13:40 UTC
    The trivial answer seemed to work for me using Perl v5.6.1 on a Sun Solaris system:
    #!/usr/bin/perl # main program: use fred; 'fred' =~ /^f(re)d$/; Fred::Fred();
    #!/usr/bin/perl # fred.pm: package Fred; sub Fred{ print "$&\t$+\n"; } 1;
    output:
    fred re
    So am I missing something?

    -M

    Free your mind

      I've tested your script and it worked fine, but why didnt the same thing work in the DB-Funktion of the Debugger?
        If you have a perl debugger then you have two symbolic universes - one for the debugging program and one for its input data, which is also a program. Could it be that you are expecting in vain that the symbols (in this case special vars) in the data should be in scope in the debugging program itself? Instead you would have to manage them in whatever synthetic symbol table you have devised for input programs to your debugger.

        -M

        Free your mind