in reply to keyword query
notice I moved the declaration of @phonesearch outside the loop, this is so the value wouldn't expire when the loop ended. The reasons for my other changes are that using while(1) is a bad idea. It sets you up for an infinite loop and could bite you in a future program if it becomes a habit. Also for this type of application it makes more sense to me to go through the lists one element at a time.my @phonesearch; my @name =<NL>; chomp(@name); my $name; while(my $phonelisting = <PB>) { chomp($phonelisting); foreach $name (@name) { if ($phonelisting =~ /$name/) { push(@phonesearch,$phonelisting); } } } print OUT "@phonesearch\n";
|
|---|