in reply to Re: Re: Passing function to a function using \&<function name> method
in thread Passing function to a function using \&<function name> method
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Passing function to a function using \&<function name> method
by Anonymous Monk on Feb 14, 2004 at 17:00 UTC | |
by edan (Curate) on Feb 15, 2004 at 06:29 UTC | |
by rich_d_thomas (Sexton) on Feb 22, 2004 at 12:21 UTC | |
by edan (Curate) on Feb 23, 2004 at 06:11 UTC | |
by rich_d_thomas (Sexton) on Mar 03, 2004 at 22:22 UTC | |
by rich_d_thomas (Sexton) on Mar 04, 2004 at 21:44 UTC | |
|