Here's a two question SOPW that I've been working on this morning.

The code below had some code removed to make it easier to follow. I'm trying to loop over the chunk until I have twice as many pictures as I asked it to find. It finds pictures, lots of them, but doesn't STOP finding them once it goes over 2X.

I know it's finding enough because I'm printing $pics_found each time through and it's way, way high.

If someone can fix THIS problem for me, that'd be great. Else I tried to do a workaround by adding a conditional near the top of the loop if ($pics_found >= $pics_to_find * 2). I tried using last and it kept going over and over again (it never found more pictures but it printed out Finished finding... forever. I then added exit and it then, well, exitted the whole script. How do I make the conditional make the while() stop?

while($pics_found <= $pics_to_find * 2) { foreach my $gal (@gals) { if ($pics_found >= $pics_to_find * 2) { print "\nFinished finding enough pictures ($pics_found)."; exit; } $pics_found = $#pics + 1; print "\nMoving on to next gallery. Currently found $pics_found +pics"; } if ($pics_found < $pics_to_find * 2) { print "We ran out of pictures to find for this search query."; last; } }

In reply to while loop not stopping 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.