CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
what's wrong?

 



why_perl
Novice

Dec 12, 2004, 5:01 PM

Post #1 of 2 (2081 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;


davorg
Thaumaturge / Moderator

Dec 13, 2004, 1:32 AM

Post #2 of 2 (2072 views)
     Re: [why_perl] what's wrong? [In reply to]  

Firstly, please don't post the same question in multiple areas of the forum. You'll waste people's time and you'll get fragmented answers to your questions.

Secondly, why post this question in the regex area? I can't see any use of regular expressions here.

I've locked this thread so no-one else can answer here.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives