sub xml_compare { # ============================================================ =item * xml_compare( $xml1, $xml2 ) - Compares xml for content Compares two dumped Perl data structures (that is, compares the xml) for identity in content. Use this function rather than perl's built-in string comparison, especially when dealing with perl data that is memory-location dependent (which pretty much means all references). This function will return true for any two perl data that are either deep clones of each other, or identical. This method is exported by default. =cut # ------------------------------------------------------------ my $xml1 = shift; my $xml2 = shift; $xml1 =~ s/(<[^>]*)\smemory_address="\dx[A-Za-z0-9]+"([^<]*>)/$1$2/g; $xml2 =~ s/(<[^>]*)\smemory_address="\dx[A-Za-z0-9]+"([^<]*>)/$1$2/g; $xml1 =~ s/(<[^>]*)\sdefined=\"false\"([^<]>)/$1$2/g; # For backwards $xml2 =~ s/(<[^>]*)\sdefined=\"false\"([^<]>)/$1$2/g; # compatibility $xml1 =~ s/<\?xml .*>//; # Ignore XML declaration $xml2 =~ s/<\?xml .*>//; $xml1 =~ s/<\!DOCTYPE perldata \[.*\]>//s; # Remove DTD $xml2 =~ s/<\!DOCTYPE perldata \[.*\]>//s; $xml1 =~ s/^\n//gm; # Remove empty newlines $xml2 =~ s/^\n//gm; return not( $xml1 cmp $xml2 ); }