Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Answer: How to Test if Two Arrays are Ordered in the Same Way

by monkfan (Curate)
on Jun 09, 2005 at 12:23 UTC ( #465085=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How to Test if Two Arrays are Ordered in the Same Way - Answer contributed by monkfan

Ok, this is one the answer given by most revered tlm to me the other day:
sub test_ordered { my ( $ref, $test ) = @_; # $i scans the indices of @$ref; # $matched keeps count of # of elements matched in @$test; my ( $i, $matched ) = ( 0, 0 ); OUTER: for ( @$test ) { while ( $i < @$ref or return 0 ) { if ( $ref->[ $i++ ] eq $_ ) { last OUTER if ++$matched == @$test; last; } } } return 1; }
More can be found here. Don't vote my root posting but vote those remarkable answers you will find there.

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2016-12-04 17:50 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (69 votes). Check out past polls.