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


Dec 12, 2004, 5:01 PM

Views: 6604
     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");

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";


Thaumaturge / Moderator

Dec 13, 2004, 1:32 AM

Views: 6595
     Re: [why_perl] what's wrong?

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
Get more help at Perl Monks