Until good indentation becomes second nature, get a copy of Perl Tidy and use it, especially before you post code here. The structure of well indented code is much easier to understand and edit correctly.

In a subtle fashion you have nested search loops. That is always a red flag, although it is sometimes unavoidable. In this case the creation of the match string for index is executed each time through your loop - that is the subtle nested 'loop'. The general fix to such nested loops is to use a hash lookup if you can in place of one of them. The following implements that in the contxt of your problem:

use strict; use warnings; my @issued_commands = qw(that or the other); my @showconfig = qw(this that and the other); my %hits = map {$_ => 0} @showconfig; my @hit; my @extra; for my $issued_CM_command (@issued_commands) { if (exists $hits{$issued_CM_command}) { ++$hits{$issued_CM_command}; push @hit, $issued_CM_command; } else { push @extra, $issued_CM_command; } } my @missed = grep {! $hits{$_}} keys %hits; print "No entry in \@issued_commands for: @missed\n" if @missed; print "No entry in \@showconfig for: @extra\n" if @extra;

Prints:

No entry in @issued_commands for: and this No entry in @showconfig for: or

Note that there is probably a lot of magic going on in there that is a little beyond where you are at with Perl at present. That is by intent! Please read the perldoc's for any Perl functions you aren't familiar with. If you still can't come to grips with it, please ask!


True laziness is hard work

In reply to Re: if else statement check an array by GrandFather
in thread if else statement check an array by sqspat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.