Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: List Compare

by BrowserUk (Pope)
on Oct 21, 2005 at 14:51 UTC ( #502020=note: print w/replies, xml ) Need Help??

in reply to List Compare

I'm not sure that 'leftSubset' is the best name, but it should work for any type of values. Though, if you want '2' to compare equal to '2.0', you'll need to tweak it.

It takes a references to the two arrays, the master first, the variable array second, and returns true false.

#! perl -slw use strict; use List::Util qw[ first ]; sub leftSubset{ local $^W; my( $major, $minor) = @_; return @{$minor} == first{ $major->[ $_ ] ne $minor->[$_] } 0 .. @{$minor} } my @a = 'a' .. 'f'; print "\n@$_\n is left subset of \n@a: ", leftSubset( \@a, $_ ) ? 'YES' : 'NO' for ['a'..'c'], ['b'..'d'],[qw[a a b c]],[ reverse 'a'..'c'];; __END__ P:\test>junk2 a b c is left subset of a b c d e f: YES b c d is left subset of a b c d e f: NO a a b c is left subset of a b c d e f: NO c b a is left subset of a b c d e f: NO

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://502020]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2018-07-22 03:17 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (451 votes). Check out past polls.