On Fri, Apr 17, 2009 at 18:01, Jim Gibson <jimsgib...@gmail.com> wrote: > On 4/16/09 Thu Apr 16, 2009 2:25 PM, "Chas. Owens" <chas.ow...@gmail.com> > scribbled: > >> 2009/4/16 Jim Gibson <jimsgib...@gmail.com>: >> snip >>> This calls the new method in package vpu and assigns the return value, which >>> should be a blessed scalar of some type, usually a reference to a hash, but >>> it could be any scalar. >> snip >>> $vpu must be a blessed scalar in order to call methods on it. Packages >>> netElement::vpu and vpu are not the same. >>> >>> It is also possible that the new() method has not returned a valid object >>> (blessed scalar) for some reason. You should look at the source code for the >>> new() method and see why that might be. >> snip >> >> Nit picking: you can only bless references, not all scalars. > > Thanks for the clarification. I believe you can bless any scalar, but the > result, the return value from the bless function, is a reference to that > scalar. snip
Why just believe something you can easily test? perl -le 'my $s = "foo"; my $o = bless $s, "Class"; print ref $o;' Can't bless non-reference value at -e line 1. snip > I always use hash references for object instances, but there are > some conditions under which using a string or an integer might be > advantageous. snip There are occasionally good reasons to bless other references. For instance Inside Out Objects[1] use a bless'ed scalar reference. Another example would be lexical filehandles, they are bless'ed typeglobs. 1. http://www.stonehenge.com/merlyn/UnixReview/col63.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/