At 7:12 PM -0800 11/16/11, blawson wrote:
Hi, I'm a newbie to perl and am having trouble with list vs scalar.
There is
an example in Programming Perl where an object is blessed and returned
from its constructor as:
                        return bless \$value => $class;
I am very unclear what is happening here. The class name is returned
but
exactly how are the $value reference and $class related?

Read the documentation for bless: 'perldoc -f bless'

       bless REF,CLASSNAME
       bless REF
               This function tells the thingy referenced by REF that it is now
               an object in the CLASSNAME package.  If CLASSNAME is omitted,
               the current package is used.  Because a "bless" is often the
               last thing in a constructor, it returns the reference for
               convenience.  Always use the two-argument version if a derived
               class might inherit the function doing the blessing.  See
               perltoot and perlobj for more about the blessing (and
               blessings) of objects.

The return value of bless is \$value, a reference to the scalar variable $value. The reference becomes an "object" of class $class. The '=>' operator is equivalent to a comma. The class name ($class) is not returned. It is a parameter to the bless operator, which returns the "blessed" reference value \$value.

See also 'perldoc perltoot' and 'perldoc perlobj' as recommended.



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to