in reply to Learning Perl - Question About Using a For Loop To Pull Data From an Array

Learning to use the Perl debugger will help you with understanding stuff like this. You can inspect the values of variables and see how instructions change them. In particular, you could put a watchpoint on $counter so you would see the values being used.

I hate to see such sloppy programs being used as examples!

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

  • Comment on Re: Learning Perl - Question About Using a For Loop To Pull Data From an Array

Replies are listed 'Best First'.
Re^2: Learning Perl - Question About Using a For Loop To Pull Data From an Array
by aUserName (Initiate) on Apr 01, 2016 at 20:20 UTC

    I have never used perl before and I am only on the third chapter of the book so I had not known about the watch function.

    Thank you for taking the time to provide a link to the documentation for me.

      This book is highly, very highly suspect if it presents code like this as examples!

      Print is your main friend. I very seldom use the debugger, even when developing C code. The debugger is yet another thing to learn at this early stage. I recommend getting good at writing print statements. Look at the difference say between: print "@names\n"; and print @names;.

      As another tip for you, add the statement use warnings as the second line in the code. Run the code using some bogus input number like 99, both with and without this statement. In one case, you just get a blank output and in the other you get a run time warning that something went wrong and a clue to what line did it!

      I don't want to overwhelm you with advice, please keep experimenting! You are going GREAT so far.