in reply to generate file from a listbox
The reason you're getting 1 2 again, instead of 5 6, can be quickly visualized with the following 2 modifications:
First, add Data::Dumper to the top of the program:
use strict; use warnings; use Data::Dumper; # Add this line
And then display what's happening in the subroutine compile by adding a printf near the end:
sub compile{ $all = $waybox->index('end'); print "$all\n"; for(my $num = 1;$num <= $all;$num++){ my $new = $num-1; my $sel = $waybox->get($new); print "TFD> sel <$sel>\n"; chomp ($sel); push(@latlong, $sel); } # liverpole -- Add a "Temporary for debug" print statement printf "TFD> latlong => %s\n", Dumper(\@latlong); $go = 1; }
What you'll then see, following your instructions above, is that when you connect the first time (with points "1 2" and "3 4"), you get the expected:
TFD> latlong => $VAR1 = [ '1 2', '3 4' ];
But the second time you connect, after adding "5 6", you get:
TFD> latlong => $VAR1 = [ '1 2', '3 4', '1 2', '3 4', '5 6' ];
So you probably just need to clear the points from the @latlong, perhaps at the end of the block in sub sftp:
if ( $go == 1 ){ # ... @latlong = ( ); }
Note, however, that you may need to lock the shared data structure @latlong, both in the parent thread and the child, wherever it is being changed (unless your flag $go is correctly handling any race conditions).
Update: Looking at some of your code more in-depth, you may want to put a delay everywhere you have a tight loop, so that it doesn't hog cpu time. For example:
for(;;){ if( $progress == 0){last} # Pause for 1/10th of a second to be a good citizen select(undef, undef, undef, 0.1) }
|
|---|