Документация
HTML CSS PHP PERL другое

Section 12.12.  Faster Getters and Setters

 
Previous
Table of Contents
Next

12.12. Faster Getters and Setters

Because we're going to play nice and always call the getters and setters instead of reaching into the data structure, getters and setters are called frequently. To save a teeny-tiny bit of time, we might see these getters and setters written as:

## in Animal
sub color     { $_[0]->{Color} }
sub set_color { $_[0]->{Color} = $_[1] }

We save a bit of typing when we do this, and the code is slightly faster, although probably not enough for us to notice it with everything else that's going on in our program. The $_[0] is just the single element access to the @_ array. Instead of using shift to put the argument into another variable, we can simply use it directly.


Previous
Table of Contents
Next
© 2000- NIV