in reply to sublist of a list
It's cheap, but the first thing I thought of was to serialize the lists and use index to see if one is a substring of the other. Something like...
sub serialize { my @copy = @_; foreach my $o ( @copy ) { $o =~ s/\\/\\\\/g; # escape escape char $o =~ s/,/\\,/g; # escape delimiter } return join q{,}, @copy; } sub in_list { my ( $la_ref, $lb_ref ) = @_; my @la = @{$la_ref}; my @lb = @{$lb_ref}; return ( !@la || 0 <= index serialize( @lb ), serialize( @la ) ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sublist of a list
by ikegami (Patriarch) on Nov 02, 2008 at 21:35 UTC |