On Tue, Jan 27, 2009 at 12:27:56AM +0100, Aristotle Pagaltzis wrote:
: * Aristotle Pagaltzis <[email protected]> [2009-01-02 23:00]:
: > That way, you get this combination:
: >
: > sub pid_file_handler ( $filename ) {
: > # ... top half ...
: > yield;
: > # ... bottom half ...
: > }
: >
: > sub init_server {
: > # ...
: > my $write_pid = pid_file_handler( $options<pid_file> );
: > become_daemon();
: > $write_pid();
: > # ...
: > }
:
: It turns out that is exactly how generators work in
: Javascript 1.7:
: https://developer.mozilla.org/en/New_in_JavaScript_1.7
As I said before, it's trivially easy to return a closure, and I
generally like my closures to be explicit:
sub pid_file_handler ( $filename ) {
# ... top half ...
return {
# ... bottom half ...
}
}
If you tell me that another language does something a particular way,
I'll take it as a possible recommendation maybe 10% of the time,
and as a dire warning the other 90% of the time. :)
Larry