How can you create an object of a class in a package?

Answers were Sorted based on User's Feedback



How can you create an object of a class in a package?..

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

How can you create an object of a class in a package?..

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

How can you create an object of a class in a package?..

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

How can you create an object of a class in a package?..

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

Post New Answer

More CGI Perl Interview Questions

What is the function of cgiwrap in cgi programming?

0 Answers  


Create a function that is only available inside the scope where it is defined ?

0 Answers  


What are the various perl data types based on the context?

0 Answers  


What is the peculiarity of returning values by subroutines in perl?

0 Answers  


what are the two ways to get private values inside a subroutine or block?

0 Answers  






Which guidelines by Perl modules must be followed?

0 Answers  


Explain the functioning of conditional structures in perl.

0 Answers  


Explain grooving and shortening of arrays?

0 Answers  


How can we create perl programs in unix, windows nt, macintosh and os/2 ?

0 Answers  


Does Perl have reference type?

0 Answers  


Comment on array slicing and range operator

0 Answers  


How will you create a file in perl?

0 Answers  


Categories