Klaus Jantzen wrote: > Hi, > > in the paper "The Singleton Design Pattern" by b. d. foy [The Perl > Review (0,1) p.19] the constructor > (listing 1, line 12) says > >> $singleton = bless \$self, $class; << > i.e. it uses the reference to $self whereas in other documentation I > always find > >> bless $self, $class; << > i.e. $self is used directly. > > Is the reference to $self necessary just because of the singleton property? > Is it/should it be used generally? > Is the second form of the bless "better"? > What is the reason for the different uses?
In general a constructor will create an anonymous hash or array with a reference to that data in $self. The code you mention is different in that it requires only a single scalar to store all the data for an instance of the class. It is also confusing in that in the constructor it uses $self as the data itself instead of the reference (in the other methods it goes back to using $self in the usual way). Think of it as: my $data = 0; my $self = \$data; bless $self, $class; and it should become clearer. For those interested, the article can be found on page 19 of http://www.theperlreview.com/Issues/The_Perl_Review_0_1.pdf HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>