ref:
But note that
qr//
scalars are created already blessed, soref qr/.../
will likely returnRegexp
.
Does "likely" mean, that ref qr/.../
could also return something other than Regexp
I think it's referring to the fact that someone could rebless the regex, warning that ref($something) eq 'Regexp'
isn't 100% reliable.
use 5.010;
my $x = qr/a/;
say ref($x);
bless $x, "Foo";
say ref($x);
say "a" =~ /$x/;
Regex
Foo
1
On top of the above false negative, a false positive is also possible, since someone could bless something that's not a regex into Regexp
. reftype
is a better tool.
use 5.010;
use Scalar::Util qw( reftype );
my $re = bless(qr/a/, "Foo");
my $not = bless({}, "Regexp");
say ref($re), " - ", reftype($re);
say ref($not), " - ", reftype($not);
Foo - REGEXP
Regexp - HASH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With