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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.