
why_perl
Novice
Dec 12, 2004, 5:01 PM
Post #1 of 2
(1253 views)
|
what's wrong?
|
|
|
Can someone tell me what's wrong with this? I've tried using next and last, elseif, 1 line if's after the push stuff, etc... The @InvalidItms gets all the values 3 times and the @ValidItms gets only the value of the identical pair. Thank you. @Array1 = ("item_one", "item_two", "item_three"); @Array2 = ("this_one", "item_two", "this_three"); @ValidItms; @InvalidItms; foreach $itm (@Array1) { foreach $sub_itm (@Array2) { if ($itm eq $sub_itm) { push (@ValidItms, $itm); } else { push (@InvalidItms, $itm); } } } print "Valid Items: @ValidItms"; print "<br>"; print "Invalid Items: @InvalidItms"; exit;
|