This is for debugging purpose. I’ve got a for loop that generates some output to Cygwin bash’s CLI.
I know that I can redirect outputs to text files and use Perl or even just a normal text editor to inspect the values printed out for a particular iteration, just feel that a bit painful.
What I am now thinking is, to place a special subroutine inside the for loop, so that it would be “interrupted” at the beginning of each iteration, and Perl script should only resume to run after user/programmer hits a key(the Enter Key from keyboard?)
In this way I can directly inspect the values printed out during each iteration.
Is there a simple way to do this, without using additional libraries/CPAN?
If you just want to pause for user input each iteration, then just do a read from STDIN inside your loop:
If the debug flag is set, then the program will pause until the user presses enter, then the loop will resume. You can print your variables before the pause. Set
$debug = 0to disable the pause.