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).
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |