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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a perl references?

686


How to start perl in interactive mode?

779


What is the use of '>>' in perl?

728


Distinguish my and local?

714


How do I replace every TAB character in a file with a comma?

759


Explain join function in perl?

718


You want to download the contents of a url with perl. How would you do that?

665


How do I send e-mail from a Perl/CGI program on a Unix system?

760


Who created perl?

697


Elaborate on perl bite-wise operators.

682


Explain what is lvalue?

769


How do you give functions private variables that retain their values between calls?

732


How to code in perl to implement the tail function in unix?

704


Which has the highest precedence, List or Terms? Explain?

692


What is the use of now constructor in perl?

742