in reply to Matching arrays

Assuming they are both sorted lists this will find if @$s is in @$a

sub in_ordered_set { my ($s,$a)=@_; return 1 unless @$s; return 0 unless @$a; my ($i,$j)=(0,0); while ($i<@$s) { while ($j<@$a) { last if $a->[$j]==$s->[$i]; return 0 if $a->[$j]>$s->[$i]; $j++; } return 0 if $j>=@$a; # Updated $j++; $i++; } return 1 }

But generally you will want to do this lookup many times on @$a so in that case you should build a hash.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

• Update:  
Fixed bug in code: would return true trying to find 3,4 in 1,2,3.