Hi,
So I found out that Win32::Ole and threads don't go well together, and Alarms are difficult to get working on Win32.
I need to time user's input and feed the next instructions with some default values when no input is received in STDIN within a given period. If I call read_excel directly, it will work just fine. If i will call it within a thread, then I will still have to press enter before the script can continue executing. But I need to do it this way, otherwise I'll have another problem with Win32::OLE and threads being not compatible (i.e., the program crashes).
I swear I made this work before but when it was time to clean up my code and re-arrange everything, it stopped working. And I couldn't CTRL+Z anymore in Padre because I already closed the file.
I'm on Windows 7, perl 5.14.2 if that helps.
use 5.014; use threads; use threads::shared; my $input : shared; my $inthread = threads->new (sub { $SIG{KILL} = sub { threads->exit(); }; print "Enter something: "; chomp ($input = <STDIN>); }); sleep 5; if (not defined $input) { $inthread->kill('KILL')->detach; } else { print "we got $input!"; } my $message = 'HELLO FROM SUB!!!\n'; my ($excelthread) = threads->create('read_excel', $message); #read_excel($message); say "\nNEW THREAD SUCCESSFULLY CREATED"; sub read_excel{ say shift; }
In reply to Timed STDIN input via threads on Win32 by markperlb0y
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |