Nice. Have you considered turning this into a module?
Another way to do this is to use HTML::PrettyPrinter or somesuch and do a string-wise comparision. That way it's easier to find how the code differes (using string diff tools) if needed, but it's probably a lot slower.
There's an (inherited) bug in your code. It leaks memory. You need to free the circular references in the tree by using the delete method:
sub cmpHtml { ... my $cmp = cmpHtmlElt ($root1, $root2); $_->delete for $root1, $root2; return $cmp; }
As a parenthesis I'd like to share this little trick:
which you use make plenty use of can be replaced with$cmp = EXPR; return $cmp if $cmp;
(assuming scalar context) though that may be a bit too obfuscated to use in public code. :-){ return EXPR || next }
lodin
In reply to Re: cmp two HTML fragments
by lodin
in thread cmp two HTML fragments
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |