Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Search in array from match in another array, print once only.

by tmharish (Friar)
on Feb 22, 2013 at 10:11 UTC ( #1020121=note: print w/replies, xml ) Need Help??


in reply to Re^2: Search in array from match in another array, print once only.
in thread Search in array from match in another array, print once only.

Track counts instead of assign 1 to hash:

use strict ; use warnings ; my @array = ( "54321", "54312", "5999", "54352", "12345" ) ; my @original = ( "12345" , "54321" , "12345" ) ; my %count ; map( { $count{ $_ }++ } @original ); print "". ( ( $count{ $_ } ) ? "$_ Found $count{ $_ } times.\n" : "$_ +Not Found\n" ) foreach ( @array ) ;

Output:

54321 Found 1 times. 54312 Not Found 5999 Not Found 54352 Not Found 12345 Found 2 times.

Replies are listed 'Best First'.
Re^4: Search in array from match in another array, print once only.
by satans-nightmare (Initiate) on Feb 22, 2013 at 11:50 UTC
    Thanks a million guys!! Much appreciated! I can use each of these in different areas. Now just for me to go sit rewrite everything in my code to open the files and get arrays of the data. Again, thanks a mill for the help!!
Re^4: Search in array from match in another array, print once only.
by garikapati (Initiate) on Feb 22, 2013 at 11:13 UTC

    just try this one

    #!C:\Perl64\bin -w use strict; my @array = ( "54321" , "54312" , "5999" , "54352" , "12345" ); my @original = ( "12345" , "54321" , "12355" ); my $hash={}; foreach my $val(@original){ if (grep{$_ == $val} @array){ $hash->{$val}++; }##end if else { print "$val NOT MATCHED\n"; }##end else }##end foreach foreach (keys(%{$hash})){ print "$_ matched $hash->{$_} times\n"; }##end foreach

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020121]
help
Chatterbox?
[LanX]: but do you have a car?
[TCLion]: Ok I have used SoPW, any feedback would be appreciated
[Eily]: yes, but if you have to borrow it please don't leave any parselmouth stains on it!
[TCLion]: was wondering why is the code window so small for SoPW?
[LanX]: qu'est-ce que c'est?
[LanX]: oh millennial folklore. ..

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2017-03-23 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (292 votes). Check out past polls.