Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl OOP

         

Davo1977

3:26 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



I want to know?

sub new
{
my ( $class %args ) = @_;
bless {_name=> %args {name},
_alias=> $args {moniker},
_langs=> $args {langauges}
} , ref ($class) ¦¦ $class;
}

What does the code ref ($class) ¦¦ $class; part of the code mean?

phranque

9:25 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



if $class is a reference, ref ($class) returns the type of object it refers to.
otherwise it returns an empty string which is FALSE in scalar context, so ref ($class) ¦¦ $class returns the value of $class in this case.

the purpose of the entire bless statement is to create an anonymous hash and tell it that it is now an object of the package named or referred to by the $class variable.