in reply to Re: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?
in thread Specific Regex with Multilines (/s and /m): Why Doesn't This Work?

Thank you--I thought that because I was wanted all of the matches (there are several in the full text to be searched), I needed /g. But I don't because I'm pushing each into an array individually, right?

  • Comment on Re^2: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?

Replies are listed 'Best First'.
Re^3: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?
by ikegami (Patriarch) on Jul 21, 2011 at 19:45 UTC

    But I don't because I'm pushing each into an array individually, right?

    Depends. As long as you can only have one match per line, then yes, the following would do:

    while (<>) { if (/.../) { push @matches, ...; } }

    If you can have multiple matches per line, you'd need something like:

    while (<>) { while (/.../g) { push @matches, ...; } }

    It's moot, however, since you want to match text that span multiple lines. You want something more like the following:

    my $file; { local $/; $file = <>; } # Slurp file. while ($file =~ /.../g) { push @matches, ...; }