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 use of –w?

0 Answers  


what is the function that is used to identify how many characters are there in a string?

0 Answers  


How to concatenate strings with perl?

0 Answers  


Explain the different types of data perl can handle.

0 Answers  


How do I print the entire contents of an array with Perl?

0 Answers  






What is the difference between single (') and double (") quote in a string in perl?

0 Answers  


how to install a package in perl ????

2 Answers  


Distinguish my and local?

0 Answers  


Consider the following example #! /bin/perl use strict; sub sample { my @arr=(1,2,3,4); return @arr; } my ($a,$b,$c,$d) = &sample; print "$a\n$b\n$c\n$d\n"; In the above code, How can I get the $c without using the arguments such as $a,$b. I don't want to use any array to get the return values.

2 Answers  


How would you ensure the re-use and maximum readability of your perl code?

0 Answers  


What are the features of perl language?

0 Answers  


Explain the difference between "my" and "local" variable scope declarations. ?

0 Answers   HCL,


Categories