nohat has asked for the wisdom of the Perl Monks concerning the following question:
I have a subroutine that returns subroutines that I use as callbacks for TK. Is it possible for the anonymous subroutines returned by my make_read_file_proc() subroutine to be recursive? That is, is it possible for anonymous subroutines to call themselves? If so, how?
Here is my function so far: (there might be errors here, I have only proved it correct (er, written it), not tried it)
-- nohatsub make_read_file_proc { my $fh = shift; return sub { if eof($fh) { $root->fileevent($fh, "readable", undef); $fh->close; $nextfile = get_next_file(); # do stuff to start processing next file # this is where I want to call myself recursively, # if I could } if (<fh>) { #do stuff to process output from forked children here #right now, just print print; } else { print "error\n"; $root->fileevent($fh, "readable", undef); undef($fh); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive anonymous subroutines
by BrowserUk (Patriarch) on Oct 07, 2003 at 23:35 UTC | |
by tilly (Archbishop) on Oct 08, 2003 at 02:56 UTC | |
|
Re: Recursive anonymous subroutines
by pg (Canon) on Oct 08, 2003 at 01:04 UTC | |
by nohat (Initiate) on Oct 08, 2003 at 14:51 UTC | |
|
Re: Recursive anonymous subroutines
by nohat (Initiate) on Sep 21, 2006 at 07:59 UTC |