On Fri, 9 Jul 2004 02:55:41 -0700, John W. Krahn wrote > > Perhaps you should keep the localtime data local to the sub (sort of > like a closure.) > > { my %data; > sub getDateTime { > unless ( %data ) { > @data{ qw[sec min hour day mon year wday yday isdst] } = > localtime $^T; $data{ year } += 1900; $data{ > mon }++; } return %data; } } >
I read about closures in the the o'reilly objects, classes and references book, but I don't think it sunk in. Would this work if this sub is in a module? Does this basically make %data the equivalent of a Java static, where all calls to the sub get the same variable? If the caller undefs all references to %data, won't %data disappear? I don't see how the syntax of putting it in another set of braces makes it a closure (don't have the book with me today). Anyway if you have time to answer any of these issues I would appreciate it. For now, until I can prove (at least to myself) that $^T is changing I'm going to leave the code as it is, but I would like to understand more about closures (not sure that's for a beginner's forum?). Thanks again, -John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>