Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Perl Regular expression

I am trying to debug a few regular expressions using:

perl -Mre=debug file.pl

The file.pl script has many regular expression. Some of them are repeated. Using the above syntax, all the regexes in file.pl are being debugged.

Is there a way to tell Perl to debug only a particular regex in a script?

I am familiar with the YAPE::Regex module, but that is not what I require. So please don’t suggest to use that.

like image 548
AnonGeek Avatar asked Jun 20 '12 20:06

AnonGeek


People also ask

How do you breakpoint in Perl?

A temporary(one-time-only) breakpoint can be set with the use of c-command by supplying a line number: DB<15> c 12 main::(debugtest:12): &readsubdirs($vardir); The argument 12 specified with the c-command tells the debugger to set a temporary breakpoint at line 12 and then continue execution.

How do I debug a Perl code in Visual Studio?

Open a Perl source file, click "Run -> Start Debugging" or hit F5 and observe there is no error as before. Now explore all VSCocde IDE functions working nicely with Perl!


2 Answers

As with many other pragmas, you can use no to cancel previous use.

use re 'debug';

$str=~/\d{3}/;

no re 'debug';

$str=~/\d{3}/;
like image 92
Oleg V. Volkov Avatar answered Sep 25 '22 21:09

Oleg V. Volkov


As of 5.9.5 the directive use re 'debug' and its equivalents are lexically scoped, as the other directives are.

Use:

{
    use re 'debug';
    # Debugged regexp here.
}
like image 44
Denis Ibaev Avatar answered Sep 26 '22 21:09

Denis Ibaev