How can you create an object of a class in a package?
Answers were Sorted based on User's Feedback
Answer / sh faisal
package Test;
sub new
{
$class = shift;
$self = {};
bless $self,$class; # By Mistake earlier i wrote it as
#$ref
return $self;
}
1;
# In perl Script
use Test; # Include the module you have created
$obj=new Test; # creating an onject of Class Test
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / vipul dalwala
Say Pachage is My Package
package MyPackage;
sub method() {
}
Then U can create Object
$myobject = new MyPackage();
and u can call any method of object like:
$myobject->method();
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / bhagwat gupta
--Like you do in any perl programme.
package PackageName;
use RelativePath::ModuleName;# The Class as per your questn
...
...
my $object = ModuleName->new();
...
...
1;
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / shah faisal
package Test;
sub new
{
$class = shift;
$self = {};
bless $ref,$class;
return $ref;
}
1;
# In perl Script
use Test; # Include the module you have created
$obj=new Test; # creating an onject of Class Test
| Is This Answer Correct ? | 2 Yes | 3 No |
what is the function that is used to identify how many characters are there in a string?
How would you ensure the re-use and maximum readability of your perl code?
what are the strategies followed for multiple form interaction in cgi programs?
What are prefix dereferencer?
How will you get the count of parameters passed to a perl subroutine?
What is hash?
What are the different ways to run cgi?
What is caller function in perl?
How can you create anonymous subroutines?
How to close a file in perl?
Explain cpan?
Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?