On Thursday 20 Feb 2003 11:24 am, Philipp Gruemmer wrote: > Hello > > I'm just minutes away from bashing the famous 'head against the > monitor'. Here's my problem: > > I have an array, let's name it @input. Another array, @blacklist, > contains lines which should be matched against the @input array and > then do something. > > I tried something like: > > foreach $line (@input) > { > foreach $cond (@blacklist) > { > if ($line =~ /$cond/) {print "True"}; #or do sth. else here. > #Just an example > }; > }; > > Isn't shis code supposed to read the first line of the @input array then > read the first line of the @blacklist array, see if the $line contains a > $cond and then ptrint "true". After that it should carry on with the second > line from both arrays....
Do you mean that if the condition suceeds you want to print "True" and then skip the rest of the @blacklist array? If so, simply put a 'last' inside your condition. The code below demonstrates what I mean. [gary@gary gary]$ cat t #!/usr/bin/perl -w my @input=('one','two','three'); my @blacklist=('two','four'); foreach $line (@input) { foreach $cond (@blacklist) { print "$line=$cond..."; if ($line=~/$cond/) { print "true\n"; last; } print "false\n"; } } [gary@gary gary]$ > > I tried several variants, which all produced some weird output (either too > less or to many matches etc.). > > What am I missing here? > > I greatly appreciate your help. > > Greetings, Philipp -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]