Please note that if you know the number of capture groups that you need per match, you can use this simple approach, which I present as an example (from 2 capture groups).
Suppose you have some data
my $mess = <<'IS_YOURS'; Richard Rich April May Harmony Ha\rm Winter Win Faith Hope William Will Aurora Dawn Joy IS_YOURS
With the following regex
my $oven = qr'^(\w+)\h+(\w+)$'ma;
I can capture all 12 (6 pairs, not 8 ... Harmony escaped and Joey is missing) in @box below.
my @box = $mess =~ m[$oven]g;
If I want to βparseβ the box details, I could just do:
my %hash = @box;
Or I could just skip the box completely,
my %hash = $mess =~ m[$oven]g;
Note that %hash contains the following. The order is lost, and duplicate keys (if any) were squeezed:
( 'April' => 'May', 'Richard' => 'Rich', 'Winter' => 'Win', 'William' => 'Will', 'Faith' => 'Hope', 'Aurora' => 'Dawn' );
YenForYang May 28 '19 at 6:30 a.m. 2019-05-28 06:30 a.m.
source share