Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @ISA array in perl?

Tags:

perl

our @ISA = "Critter";

In which condition will I use @ISA?

and why our @ISA?.

like image 572
user1363308 Avatar asked Jan 06 '13 11:01

user1363308


People also ask

Can() in Perl?

The can() method accepts the method's name as a string. It returns a reference to the existing function that implements this method or else it returns a false value. This method can be called on a class, object, or a package.

What is class and object in Perl?

Object Basics The object is stored as a reference in a scalar variable. Because a scalar only contains a reference to the object, the same scalar can hold different objects in different classes. A class within Perl is a package that contains the corresponding methods required to create and manipulate objects.

What is INC Perl?

@INC is a special Perl variable that is the equivalent to the shell's PATH variable. Whereas PATH contains a list of directories to search for executables, @INC contains a list of directories from which Perl modules and libraries can be loaded.


1 Answers

To extend Mat's comment, stuff like this is extensively documented in the perldocs.

Regarding @ISA, here's what it says:

A Class is Simply a Package

...

Each package contains a special array called @ISA . The @ISA array contains a list of that class's parent classes, if any. This array is examined when Perl does method resolution, which we will cover later.

It is possible to manually set @ISA , and you may see this in older Perl code. Much older code also uses the base pragma. For new code, we recommend that you use the parent pragma to declare your parents. This pragma will take care of setting @ISA . It will also load the parent classes and make sure that the package doesn't inherit from itself.

However the parent classes are set, the package's @ISA variable will contain a list of those parents. This is simply a list of scalars, each of which is a string that corresponds to a package name.

our and @ISA go hand in hand because @ISA is expected to be a package variable.

like image 158
Zaid Avatar answered Sep 17 '22 16:09

Zaid