We don't bite newbies here... much | |
PerlMonks |
Foreach/While - Why does this run AFTER that?by CalebH (Acolyte) |
on Oct 05, 2014 at 20:04 UTC ( [id://1102886]=perlquestion: print w/replies, xml ) | Need Help?? |
CalebH has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Monks! Recently I was asked to write a script for a friend to hash check a torrent file against data on their drive. I found a script online that did similar, and edited it around a bit. (I added the portion to split the file on disk and hash check it.)
Now, my intended goal was for the script to compare the pieces from the .torrent file against the file stored on disk, one piece at a time, and if the hashes matched let the user know. The problem is that the script will only output the following -
Now, the hashes all match up, but unfortunately the script is not running as it should. 'dothis' should be executing along with 'dothat', but doesn't run until after 'dothat' finishes. I realize that the while loop is ran once the first piece is counted ($p), and then the script continues the while loop until it finishes and then goes back up. (This is obvious by the logfile - 'Hash:', and 'Counted' never change, where Hash: should be matching with the Hash2: in the logfile, and printing HashMatch, and the Counted: section should be matching Count:). What I don't understand is WHY, since it's in a foreach loop first and $p should increment with every iteration of the while loop, correct? I also don't understand how to fix this, and I have tried several different things, including moving around the } towards the end to see if possibly I had put them in the wrong spots, as well as adding dothis and dothat in subroutines at one point, and calling them from each other. Aside from changing the order that these two run in, I still get the same results with every change I try to make. During the first round of edits, I had a problem where every single run would increase the size of $p, to the point where it's length went over 250 characters, and grew with every iteration. I appreciate all the help, and after a week of trying to figure out what I am doing wrong (and going through about 12 different Perl books that I own), I am stumped.
Back to
Seekers of Perl Wisdom
|
|