If I were you I would reword my question a bit. You aren't comparing two lists of sorted numbers, really, but rather two lists of "things". You want to check everything in list1 to see if it is in list2. If it is, go for a party! If not, go to a different party! (Sorry, early Friday morning sense of humour there). So, you could write it like this:

my @list1 = (1,3,4,5,6,7); my @list2 = (1..100); foreach my $list1_item (@list1) { my $flag = 0; foreach my $list2_item (@list2) { if ($list1_item == $list2_item) { $flag = 1; last(); } } if ($flag == 0) { print $img1; } else { print $img2; } }

So basically we just loop over list1, see if it's elements are in list2. If they are, set the flag variable, stop looping and print it. If they aren't, print the alternate image. There are definitely more concise and efficient ways to code that, but this is clear and will work if you move from numbers to strings, objects, etc.

-Tats

In reply to Re: Real confusion with loops and counters by Itatsumaki
in thread Real confusion with loops and counters by Anonymous Monk

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.