Does anyone know why the timeout does not work when I use the `<system command>` for performing system commands?

No. I tested it with `cmd`, and it works fine for me. I am on Linux, and it sounds like you are on Win32, so maybe it's an OS thing with signals? *shrug*.

In the timeout_func function, is there a way of getting the function name from the coderef somehow ... ?

Not that I know of. You could get the name of the function from within the function itself with (caller 0)[3], but that won't help you in timeout_func (unless you set a package variable or something yucky like that). You could resort to using symbolic refs, though it's playing with fire...

timeout_func($timeout, 'myfunc', ...); sub timeout_func { my ($timeout, $func_name, @args) = @_; # ... eval { # ... { no strict 'refs'; $func_name->(@args); } } if ($@) { die "$func_name died ($@)\n"; } }

Notice that you pass the name of the function to call, instead of a hard reference to the function (the \&myfunc syntax).

--
edan (formerly known as 3dan)


In reply to Re: Re: Re: Passing function to a function using \&<function name> method by edan
in thread Passing function to a function using \&<function name> method by rich_d_thomas

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.