in reply to Why does this code continue to loop?

When I remove the sleep, the program ends in 4 seconds, printing Round 631 as the last line. As the code prints all the output for each round, it prints 1+2+3+4+...+631 "Rounds", i.e. 199396 lines, which means it would take 55 hours with the sleep included.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Why does this code continue to loop?
by rachard11 (Acolyte) on May 03, 2017 at 20:21 UTC
    OK, I now see it's not an infinite loop, it's just going through the 1+2+3+...+631 Rounds cycle, which wasn't my intent. This code is processing a file with only about a total of 30 instances of html, pdf, or txt references, so I was expecting the @output array to have only about 30 elements. The other 600-ish elements are duplicates. How do I keep each file reference from going into the @output array more than once?

      It only goes into the array once, it gets printed multiple times. Erase this

      foreach (@output) { print "Round $i\n " ; print "$_\n" ; $i++ ; sleep(1) ; }
      and put this at the end of the file.
      foreach (@output) { print "$_\n" ; }

        Thank you for the reply. When I put the print command at the end of the file, all the duplicates are still there. My original code had this snippet at the end:

        open(my $fh1, '>', $SCAC_output) ; foreach (@output) { print $fh1 "$_ \n "; } close $fh1 ;

        The $SCAC_output file (defined elsewhere in the code) has a bunch of duplicate file references from the array. The reason I ended up putting the print statement inside the while loop (along with the sleep command) was to try to understand better what part of the code causes duplicates in the array.