12

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.

2
  • 1
    Why not just comment out the other regexes, or run just the particular regex on the command line, via perl -e ? Jun 20, 2012 at 20:45
  • the script is very compilcated(12000 LOC). If I will comment out any of regex then the execution will fail..also if I provide dummy values, then it will give unexpected results :(
    – AnonGeek
    Jun 20, 2012 at 20:55

2 Answers 2

13

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}/;
6

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.
}
2
  • Is this also supported in 5.8.8? I am putting it under a condition but it is enabling it globally for all regex.
    – AnonGeek
    Jun 20, 2012 at 21:10
  • 1
    No, since version 5.9.5. In 5.8.8 you need use no statement. Jun 21, 2012 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.