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 are perl strings?

498


Explain gmtime() function in perl?

559


what are the strategies followed for multiple form interaction in cgi programs?

502


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

478


Mention the difference between die and exit in Perl?

648






How to connect with sqlserver from perl and how to display database table info?

525


Explain perl. When do you use perl for programming?

440


What is the use of "stderr()"?

564


Why do we use "use strict" in perl?

519


Write a cgi program to show the header part?

513


How to concatenate strings with perl?

470


There are some duplicate entries in an array and you want to remove them. How would you do that?

491


When does circular reference occur?

515


What happens in dereferencing?

524


List the data types that Perl can handle?

568