in reply to Can I get better approach to get solution

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Can I get better approach to get solution
by kyle (Abbot) on Feb 13, 2007 at 04:43 UTC

    This doesn't work because the number 43 appears twice in @all_data but not at all in @selected_data. Your algorithm counts it as a match when it shouldn't be.

Re^2: Can I get better approach to get solution
by Anonymous Monk on Feb 13, 2007 at 05:08 UTC
    Thanks for your help.