G'day maxamillionk,

"... the code below does something quite different from what I expect."

Without telling us what you expected to happen and what actually happened, we're left entirely with guesswork.

This code runs for me. It does not produce any exception messages. It does what I'd expect it to do. I'm sort of making a point there: you have no idea what my exceptionsexpectations were. :-)

Try adding another statement near the top (without changing anything else):

... use strict; $| = 1; ...

Does that now do what you expect? If so, your problem was buffering. Depending inon your real requirements — beyond what you have in this tiny, demo script — there's possibly better ways to handle this: see "perlvar: $|", "IO::Handle" and "Suffering from Buffering?".

For future reference, please read "How do I post a question effectively?" and (related but probably not particularly useful in this specific instance) "SSCCE".

Nothing to do with the issue at hand; however, I thought I'd point out that &main is probably not what you want here. Unless you really want it, and know exactly why you want it, choose subname() over &subname. See perlsub for more about that.

Update: Fixed typos:
s/my exceptions/my expectations/ — thanks roboticus.
s/Depending in/Depending on/ — noticed when fixing the previous typo.

— Ken


In reply to Re: Trying to make a simple countdown timer by kcott
in thread Trying to make a simple countdown timer by maxamillionk

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.