Subject: | Can not compare compiled regexps |
Data::Compare version 0.02 does not correctly compare regexps created by qr//.
For example:
use Data::Compare;
$a = qr/abc/; $b = $a;
print Data::Compare::Compare($a, $b) ? "Different\n" : "Same\n";
The output is:
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 94.
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 94.
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 94.
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 94.
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 94.
Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/5.8.0/Data/Compare.pm line 116.
Can't handle type. at -e line 1
This also occurs with perl 5.00503.
I don't think there is any way to compare regexps semantically -- ie, they would match exactly the same set of strings -- however a reasonable approximation can be obtained by stringifying them, then comparing the strings.
The attached patch adds this functionality.
--- Compare.pm.orig 2003-11-28 12:54:19.000000000 +1100
+++ Compare.pm 2003-11-28 12:54:40.000000000 +1100
@@ -80,6 +80,9 @@
}
1;
}
+ elsif ($refx eq 'Regexp') {
+ Compare($x . '', $y . '');
+ }
elsif ($refx eq 'REF') {
0;
}