sman has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone,
I'm doing some comparing between the usage of class and module. I declare a class named Foo with a instance method called hello as the following:
And the result is like this:1 package Foo; 2 3 __PACKAGE__->hello('test1'); 4 hello('test2'); 5 6 sub hello { 7 my ($self, $arg) = @_; 8 print "hello=". $arg. "\n"; 9 } 10 1;
I am a bit confused by the usage of __PACKAGE__. In terms of the result, I guess line3 is calling a object method but don't see any new() syntax. Looks like line4 is calling a regular subroutine and that's why the error happens. Am I right about this?arg=test1 Use of uninitialized value $arg in concatenation (.) or string at line + 8
Under which kind of situation should we use __PACKAGE__ to create an object instead of calling its new() in the caller program?
Thank.
Back to
Seekers of Perl Wisdom