Sunday 15 February 2015

Multi-line regex in Perl -


I have written a Perl script that parses the output of a command, looks for the work name in the output and print Does the function name

The command output looks like below

Here the work name is 'mutipleregexpression' but a part of the word 'press' is printed in new line .

  Task Name: Multirection Press  

This is regex which is currently in use in my code:

  ` $ Line = ~ / (. *): \ S * (. +) / ` 

The above regex is not printed in the new line which occupies part of the work name. It only captures 'monoleraxes', it does not capture 'press' because it is pressed into the new line.

So my question is, what is I

work to occupy the work name

  Sub get_status {my ($ self) = @_; My $ function name; My% result; My $ line; $ Self-> {'Cmd'} = # Order goes here; # Command $ self- & gt; Execute ($ self-> {'cmd'}); $ Self- & gt; {'Stdout'} = $ self-> Get_stdout (); My $ count = 0; # To cross the output via parsing the output for the $ line (@ {$ self-> {'stdout'}} {chomp $ line; if ($ line = ~ m / ^ function \ sName \: \ S + (\ w +) / msx) {$ taskname = $ 1; $ count = 0;} Elsf ($ line = ~ /(.*):\s*(.+)/) {my $ key = $ 1; My $ value = $ 2; $ result {$ functionname} {++ $ count} = $ value;}} return \% result;}  

Function call:

  My $ result = $ data- & gt; get_status ('Multilanguage expression', '1'); info ('job status:'. $ Result);  

Output:

  Unconditioned Use of Great Value is concatenation (.) Or string 114 in line 20150317T194029 Information status is the job:  

I do not even know the language, but you can try this logic :

  var current_line = External string line in empty string lines ( If in the line "do something" with the ":" {then 1. last line (current_line) or 2. Line is the beginning of a new line (what comes next after "current_line =").} And {then 1. is the continuation of the last line LINE (current_line = current_line + line).}}  

Hope this helps.


No comments:

Post a Comment