Nice ... but I'm not really sure if this qualifies as lazy !?!

You are using many copies to flatten the stack.

with some dumps of intermediate @stack-states:

#!/usr/bin/perl use strict; no warnings ; my $tree1 = [ [ [ 'a', 'b', ], 'c'],'d' ]; my $tree2 = [ ['a','b'],[ 'c','d' ] ]; my $ti1 = get_tree_iterator($tree1); my $ti2 = get_tree_iterator($tree2); my $cnt_mismatches=0; while (1) { my ($L, $R) = ($ti1->(), $ti2->()); print "L=$L, R=$R\n"; die "--- not equal!" unless ($R eq $L) or (!$L and !$R); last if !defined $L; } print $cnt_mismatches ? "$cnt_mismatches mismatches" : "TREES MATCH!", + "\n"; use Data::Dump 'dd'; sub get_tree_iterator { my @stack = (shift); return sub { print "---\n"; dd \@stack; while (@stack and ref $stack[0] eq 'ARRAY') { unshift @stack, @{shift @stack}; dd \@stack } return shift @stack; } }
out
--- [[[["a", "b"], "c"], "d"]] [[["a", "b"], "c"], "d"] [["a", "b"], "c", "d"] ["a", "b", "c", "d"] --- [[["a", "b"], ["c", "d"]]] [["a", "b"], ["c", "d"]] ["a", "b", ["c", "d"]] L=a, R=a --- ["b", "c", "d"] --- ["b", ["c", "d"]] L=b, R=b --- ["c", "d"] --- [["c", "d"]] ["c", "d"] L=c, R=c --- ["d"] --- ["d"] L=d, R=d --- [] --- [] L=, R=

Cheers Rolf

( addicted to the Perl Programming Language)


In reply to Re^2: Challenge: Perl 5: lazy sameFinge()? by LanX
in thread Challenge: Perl 5: lazy sameFringe()? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.