Created
September 17, 2010 06:55
-
-
Save tene/583838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use 5.010; | |
| use strict; | |
| use warnings; | |
| use List::MoreUtils qw/natatime zip/; | |
| my $rlp = [ 1, 2, [3, 4, [5, 6]]]; | |
| my $rlp1 = [ 1, 2, [3, 4, [5, 6]]]; | |
| my $rlp2 = [ 1, 2, [3, 4, [5, 9]]]; | |
| sub rcmp { | |
| my ($l, $r, $test) = @_; | |
| if (!(ref $l || ref $r)) { | |
| return $test->($l, $r); | |
| } | |
| elsif ((ref $l && ref $r) && (ref $l eq ref $r)) { | |
| return 0 if @$l != @$r; | |
| my $it = natatime 2, zip(@$l, @$r); | |
| while ( my($x, $y) = $it->() ) { | |
| my $rv = rcmp($x, $y, $test); | |
| return 0 unless $rv; | |
| } | |
| return 1; | |
| } | |
| else { | |
| return 0; | |
| } | |
| } | |
| say rcmp($rlp, $rlp1, sub { $_[0] == $_[1] }); | |
| say rcmp($rlp, $rlp2, sub { $_[0] == $_[1] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment