Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: List Compare by BrowserUk
in thread List Compare by anniyan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found