in reply to Match pattern per line and after another one as multiline in single file opening

Hi,

it's a bit difficult to be sure what you're trying to do without having some sample input data.

Try perhaps this:

open my $FH, '<' , $config or die "Cannot open $config: $!\n"; my $data = <$FH>; # removing a header line? or what? while (my $line = <$FH>) { next if /^\s*#|^$/; print "$1\n" while $data =~ m/\{([^}]*)\}/gx ; } close $FH;
Untested because of the absence of test data.
  • Comment on Re: Match pattern per line and after another one as multiline in single file opening
  • Download Code

Replies are listed 'Best First'.
Re^2: Match pattern per line and after another one as multiline in single file opening
by kennethk (Abbot) on Feb 14, 2017 at 23:33 UTC

    I read the description as he needs the [^}] to match through newlines, and so there needs to be a slurp before the regex. But your point about lack of test data is very appropriate.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Yeah, I may have missed or overlooked the sentence about multiline match and I really wondered why the OP code was localizing $/, but given that the OP speaks about a config file and given the regexes used for matching the data, I am still not really convinced that there is an actual need for multiline match.

      But it's impossible to say either way without the input data.