G'day haukex,

Following your CB request, I ran this a few times for you. Firstly, here's what I'm using:

$ uname -a Linux ibm-laptop.diversityarrays.com 4.1.34-33-default #1 SMP PREEMPT +Thu Oct 20 08:03:29 UTC 2016 (fe18aba) x86_64 x86_64 x86_64 GNU/Linux $ perl -v | head -2 | tail -1 This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi
"I've tried it lots of times, and no matter how long I wait to input something (or nothing) and hit enter, the output is invariably 2.

I got different results: ran it four different ways; only got 2 once.

I wrapped your one-liner in date commands to indicate the wait time; however, this didn't work when I issued an interrupt (^C). Here's the runs:

Hitting Enter almost immediately:

$ date; perl -wMstrict -le '$a=time;$SIG{ALRM}=sub{$b=time};alarm 2;<> +;print $b-$a'; date Sat Jul 21 05:55:19 AEST 2018 Use of uninitialized value $b in subtraction (-) at -e line 1, <> line + 1. -1532116519 Sat Jul 21 05:55:20 AEST 2018 $

Hitting Enter after several seconds:

$ date; perl -wMstrict -le '$a=time;$SIG{ALRM}=sub{$b=time};alarm 2;<> +;print $b-$a'; date Sat Jul 21 05:56:58 AEST 2018 2 Sat Jul 21 05:57:05 AEST 2018 $

Hitting Ctrl-C almost immediately:

$ date; perl -wMstrict -le '$a=time;$SIG{ALRM}=sub{$b=time};alarm 2;<> +;print $b-$a'; date Sat Jul 21 05:59:28 AEST 2018 ^C $

Hitting Ctrl-C after several seconds:

$ date; perl -wMstrict -le '$a=time;$SIG{ALRM}=sub{$b=time};alarm 2;<> +;print $b-$a'; date Sat Jul 21 06:00:13 AEST 2018 ^C $

Finally, please consider this response in isolation. I did start reading this thread when it first appeared; I stopped doing that when umber-hued material appeared to be headed for a cooling device. I followed the link you provided in the CB and replied directly; I didn't review any part of the thread before doing so.

— Ken


In reply to Re^14: Print inside SIGNALS by kcott
in thread Print inside SIGNALS by pedrete

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.