perl -we'use strict;use P; use Types::Core qw(typ);
my $re = qr{ab};
P "re(=%s), has ref %s, and type %s", $re, ref $re, typ $re;
'
re(=(?^:ab)), has ref Regexp, and type REGEXP
####
Binary "=~" binds a *scalar expression* to a *pattern match*.
####
perl -we'use strict;use P;
my $str="part";
my @match_m = $str =~ m{^(.).*?(.)};
my @match_qr = $str =~ qr{^(.).*?(.)};
sub p_Ar($) { P "#=%d, content=(%s)", scalar(@{$_[0]}), $_[0]};
P "res1:%s\nres2:%s", p_Ar \@match_m, p_Ar \@match_qr;
'
res1:#=2, content=(['p', 'a'])
res2:#=2, content=(['p', 'a'])
####
> perl -we'use strict; use P qw(:undef="(undef)");
my $qr_string = q((?:\G(\w)\W{2}(\w))*);
my $qr = qr[$qr_string];
my $base_pat=q(p--t);
sub p_Ar($) { P "#=%d, content=(%s)", scalar(@{$_[0]}), $_[0]};
our (@match_mstr , @match_mqr , @match_qr , @match_qr2 , @tst_names);
@tst_names = (qw(mstr mqr qr qr2));
local * p_matches; *p_matches = sub ($) {
no strict "refs";
$_ = $base_pat x $_[0];
@match_mstr = $_ =~ m{$qr_string}g;
@match_mqr = $_ =~ m{$qr}g;
@match_qr = $_ =~ $qr;
@match_qr2 = $_ =~ qr{$qr};
P qq(For str="%s:\n).(qq(%10s:%s\n) x @tst_names), $_ ,
(map { ("res_".$_, p_Ar(\@{"match_".$_})) } @tst_names);
0;
};
my $c=1;
while (3>=$c) { p_matches($c++) }
'
For str="p--t:
res_mstr:#=4, content=(['p', 't', (undef), (undef)])
res_mqr:#=4, content=(['p', 't', (undef), (undef)])
res_qr:#=2, content=(['p', 't'])
res_qr2:#=2, content=(['p', 't'])
For str="p--tp--t:
res_mstr:#=6, content=(['p', 't', 'p', 't', (undef), (undef)])
res_mqr:#=6, content=(['p', 't', 'p', 't', (undef), (undef)])
res_qr:#=2, content=(['p', 't'])
res_qr2:#=2, content=(['p', 't'])
For str="p--tp--tp--t:
res_mstr:#=8, content=(['p', 't', 'p', 't', 'p', 't', (undef), (undef)])
res_mqr:#=8, content=(['p', 't', 'p', 't', 'p', 't', (undef), (undef)])
res_qr:#=2, content=(['p', 't'])
res_qr2:#=2, content=(['p', 't'])