… | |
… | |
173 | my $arg = ...; |
173 | my $arg = ...; |
174 | |
174 | |
175 | call_me_back_later sub { $arg->method }; |
175 | call_me_back_later sub { $arg->method }; |
176 | |
176 | |
177 | Under most circumstances, closures are faster, use fewer resources and |
177 | Under most circumstances, closures are faster, use fewer resources and |
178 | result in much clearer code then the traditional approach. Faster, |
178 | result in much clearer code than the traditional approach. Faster, |
179 | because parameter passing and storing them in local variables in Perl |
179 | because parameter passing and storing them in local variables in Perl |
180 | is relatively slow. Fewer resources, because closures take references |
180 | is relatively slow. Fewer resources, because closures take references |
181 | to existing variables without having to create new ones, and clearer |
181 | to existing variables without having to create new ones, and clearer |
182 | code because it is immediately obvious that the second example calls the |
182 | code because it is immediately obvious that the second example calls the |
183 | C<method> method when the callback is invoked. |
183 | C<method> method when the callback is invoked. |