in reply to Can I get better approach to get solution

You're looking for the number of elements in the intersection between the two arrays. You're looking for this:
my %x; $x{$_} = undef for @selected_data; my %y; $y{$_} = undef for @all_data; my $total; foreach my $k ( keys %x ) { $total++ if exists $y{$k}; } print "Count -> $total\n";

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Can I get better approach to get solution
by Anonymous Monk on Feb 13, 2007 at 04:14 UTC
    dragonchild,
    that doesn't work.
    The count return from the code is "8", which is not correct, but correct result is "12".

    I would like to compare the elements in @selected_data with @all_data array, if elements from @selected_data array found in @all_data, then increment the count.
    thanks