in reply to Computing Subsets
This seems to work...
use Test::More tests => 3; my $x = "AB:APPLE:BOY:ZOO:ZOOM"; ok isSubset('APPLE:ZOO' => $x); ok !isSubset('BOY:GIRL' => $x); ok isSubset('AB:BOY:ZOOM' => $x); sub isSubset { my ($small, $big) = @_; $small =~ s{:}{:(?:[^:]+:)*}xg; return($big =~ /^(?:[^:]+:)*$small(?::[^:]+)*/); }
... but I'd generally go with an array/hash solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Computing Subsets
by grandpascorpion (Initiate) on May 27, 2012 at 22:03 UTC |