regex - Capturing groups in a variable regexp in Perl -


I have a bunch of matches that I need to make, and all of them use the same code, except it To read that file, and to regexp itself, I want to change the match into a process that only accepts the filename and regexp as a string. When I tried to use the variable to match, however, the special capture variable stopped being set.

  $ line = ~ / (\ d +) \ s (\ d +) \ s /;  

This code sets $ 1 and $ 2 correctly, but the following addresses undermine them:

  $ regexp = "/ (\ d +) \ S (\ d +) \ s / "; $ Line = ~ / $ regexp /;       

Itemprop = "text">

Use your regex string Qr:

  My $ regex = qr / (\ d +) \ s (\ d +) \ s /; My $ file = q! / Path / to / file! Foo ($ file, $ regex);  

Then in the sub:

  subfoo {my $ file = shift; My $ regex = shift; Open your $ FH, can not open '$ file' to read '& lt;', $ file or die: $! "; While (my $ line =  

Comments