Your rules for what you count are a little strange, but this produces the same result.
Update 1: No it doesn't! You caught me out with the duplication of value 43 in @all_data.
Is it any better?
C:\test>p1
use List::Util qw[ sum ];;
@selected_data = qw(13 76 90 13 77 100 76 300 13 65 400 74 89 34 65);
@all_data = qw(1 5 2 8 12 87 13 76 98 77 89 90 11 65 43 74 43 32 34 67
+);;
++$seen{ $_ } for @selected_data, @all_data;;
print sum map{ $_ > 1 ? $_ - 1 : () } values %seen;;
13
Update2: This is better.
@selected_data = qw(13 76 90 13 77 100 76 300 13 65 400 74 89 34 65);
@all_data = qw(1 5 2 8 12 87 13 76 98 77 89 90 11 65 43 74 43 32 34 67
+);
@seen{ @all_data } = ();;
exists $seen{ $_ } and $count++ for @selected_data;;
print $count;;
12
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.