in reply to Random Couple Script
1) When I execute the code, I don't get any output. That's because your function randomize has an endless loop.
This code increments $totalline until @file_contents is empty. Since there is no code that empties the array, this will never happen.while (@file_contents) { $totalline++; }
Probably you wanted to say 'foreach', so that the function tells you the size of @file_contents. But then the sub shouldn't be called 'randomize'. As a side note, you get the size of the array simply with 'scalar(@file_contents)'.
2) The splice in sub compile_list takes not only person $ng out, but $ng persons begining at position $ng. Use 'splice(@file_contents,$ng,1);'
By the way, in this sub a 'while (@file_contents)' as main loop would have been better, since you are finished when @file_contents is empty.
3) in sub makegroups you select two adjacent names out of the list, but you increment $fark only by 1. Try it out, you will see that every name except the first will be printed twice.
Ok, that's what I found out. If there is still something wrong with the script, put in 'print' statements to show you what is going on. The first thing I did with your script was to insert code like
between "interesting" lines in the sub compile_list to find out what it is doing. The endless loop was apparent immediately because the second print statement was never reachedprint "Position 1: @file_contents\n";
|
|---|