Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

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


in reply to Search in array from match in another array, print once only.

Change loop to:

foreach $string(@array) { my $found = 0 ; foreach $string2(@original) { if ($string eq $string2) { $found = 1; } } if ($found == 0) { print "$string not found\n"; } else { print "$string found\n"; } }

Also use strict and warnings ...


Comment on Re: Search in array from match in another array, print once only.
Download Code
Re^2: Search in array from match in another array, print once only.
by tmharish (Friar) on Feb 22, 2013 at 09:37 UTC

    More importantly its more efficient if you use a hash:

    use strict ; use warnings ; my @array = ( "54321", "54312", "5999", "54352", "12345" ) ; my @original = ( "12345" , "54321" , "12355" ) ; my %hash = map( { ( $_ => 1 ) } @original ) ; print "". ( ( $hash{ $_ } ) ? "$_ Found\n" : "$_ Not Found\n" ) foreac +h ( @array ) ;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2015-07-07 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls