Perl regex - store reference to regex captures in a variable -


Just wondering how this will work:

  $ my capture = qr / Perl pattern (. *) /; My string = "Pearl pattern is complex"; My $ print_it = "Printing Test: $ 1 \ n"; If ($ string = ~ m / $ capture /) {print $ print_it; }   

I tried to cite $ print_it in different ways (qw, qr, '', '"), but when I create pattern string and not set On runtime.

Around other methods, I'm sure, but it would be convenient.

EDIT: This is what I am trying to do. I want the user to provide an argument to format the input string. Like - - Format 1 Input String: "User = Usernames Resource_used_cput = 20: 00: 01 Resources_As_WithLine = 10: 00" Say I want to draw only one waletime or cputime and a flag-based user name from the command line. I was thinking of defining the set of formatting options like Usernames and CPU for username, 2 for user name and 2 for voltim. With 3 easy to do with brute force, and just define some if / again cases for match-up or match. As the scales happen, if I / I like the array in a large list of cases.

  $ format = (qr / user = (\ s +) /, qr / user = (\ s +). * Resource_used_cput = (\ d +): (\ d +): (\ d +) /, qr / user = (\ S +). * resource_james_whiteline = (\ d +): (\ d +) /); # These answers are incorrect for the reasons stated in the following: $ response = ("username is 1 dollar", "user $ 1 $ 4 seconds, $ 3 min and $ 2 hour contentum" "user $ 1 using $ 2 Hour $ 3 minutes wall time ");   

versus

  if (m / user = (\ S +). * Resource_used_cput = (\ d +): (\ d +): ( \ d +). * resource_used_nightline = (\ d +): (\ d +) /) {$ user = $ 1; $ Wall = "$ 5: $ 6"; $ Cpu = "$ 2: $ 3: $ 4"; } If ($ format == 0) {Print "Username is $ user"} Elsf ....   

I think there is a better way?

Turn on $ print_it in a code reference.

  My $ print_it = sub {"Printing Test: $ 1 \ n"}; ... Print-print_it-> (); # Or print & amp; $ print_it;    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -