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 |
How to connect to SQL server through Perl?
How can the user execute a long command repeatedly without typing it again and again?
what are the three groups involved in information sharing?
What are the various file operations in perl. Explain with example.
How will you declare a variable in perl?
Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?
What does the qq{ } operator do?
How do you you check the return code of a command in perl?
List the files in current directory sorted by size ?
Distinguish my and local?
How to read a directory in perl?
How do find the length of an array?