OK, that's a lot clearer. The basic thing you're doing wrong is using angle brackets to go through a list, which is not necessary. The angle brackets are generally associated with doing I/O.

But you're also doing a lot of unnecessary work, like the way you're counting up the number of items you're pushing into your list. Perl has constructs for doing that kind of stuff much more easily; you can even do it in one line, like this: push @list, (split ' ')[3] foreach <$syscmd>;In case that's too compact, here's the equivalent broken up a little more:

while (<$syscmd>) { my @temp = split ' '; push @list, $temp[3]; }
Of course, this also takes up more space, for the temporary array.

Your main loop searches an array for a matching element. That's a common enough construct that perl has a special construct for it, the grep function. Here's how you'd use it in this context:

foreach my $val (sort keys %prolist) { unless (grep($prolist{$val} eq $_)) { print "NF: $prolist{$val}\n"; } }
There are ways to tighten up that loop, but this lets you see what's going on. Your original code can be fixed by just taking out the angle brackets in the while, but you may as well pick up some perl nifty tricks while you're at it.

(BTW, I haven't tested any of this code.)


In reply to Re (3): loop control by VSarkiss
in thread loop control by maxl90

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.