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

How to merge two arrays in perl?

774


Hi, I am a accountant. I am preparing a balance sheet but because of staff shortage and time pressures I cant complete it on time. There is lot of common data with last years which I need not retype and I can manage by editing last year’s balance sheet ? Is their any software on net where I can do this easily??

1962


What does a die() function do in perl?

785


Explain what is STDIN, STDOUT and STDERR?

761


Explain regular expression in perl?

742


How many data types are there in perl?

756


What is Perl?

777


How will you open a file in read-only mode in perl?

705


Explain '->' in perl?

717


Why Perl aliases are considered to be faster than references?

755


What are the steps involved in configuring a server using cgi programming?

689


How to read a file into a hash array?

815


How can you replace the characters from a string and save the number of replacements?

712


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

746


Can we load binary extension dynamically?

752