in reply to how to extract multiple pattern into array
roboticus and toolic are right that you should be using a real parser for such relatively complex input. Why try to re-implement a parser when it's already been done for you by someone else? :-)
Just for completeness, how to fix your script: 1. You use local $/ = "";, which will cause the entire file to be slurped on the first iteration of the while loop, and then you only call your regex once. If you want to match once per line, remove the local $/ = "";, otherwise, you could use something like push @fields, $1 while /$reM/g; to match as many times as possible in the current string. Also, I'd change .* to being non-greedy, i.e. .*?. 2. Your regex requires a space after the opening {, but your input does not have a space there, so it will not match. I'd suggest something like \s* to match any amount of whitespace, even none.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to extract multiple pattern into array
by AnomalousMonk (Archbishop) on Feb 02, 2015 at 18:54 UTC | |
by Anonymous Monk on Feb 02, 2015 at 20:27 UTC | |
by herman4016 (Acolyte) on Feb 04, 2015 at 07:25 UTC |