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 use of –w?
what is the function that is used to identify how many characters are there in a string?
How to concatenate strings with perl?
Explain the different types of data perl can handle.
How do I print the entire contents of an array with Perl?
What is the difference between single (') and double (") quote in a string in perl?
how to install a package in perl ????
Distinguish my and local?
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.
How would you ensure the re-use and maximum readability of your perl code?
What are the features of perl language?
Explain the difference between "my" and "local" variable scope declarations. ?