Introduction to Packages
Get introduced to Perl packages in this lesson.
We'll cover the following
Like C++ and Java, Perl also supports object-oriented programming. In order to do this in Perl, we create packages and objects. Let’s learn more about them.
What are packages?
Packages are the blueprints of objects. A package is a user-defined data type, which includes local methods/subroutines and local variables.
What are objects?
An object is an individual instance of the package. We define a package once and then create different instances of that package. Each object is allocated its own memory space.
Objects have two components:
- property
- method
Property
Property is essentially the variables inside the package or object.
Method
Methods refer to the subroutines inside the package or object.
Why use packages?
Packages and Objects are used to make your code more efficient and less repetitive by grouping similar tasks. A package is used to bundle the properties and associated methods together as a blueprint. The package is defined as a concept and objects are instantiated to represent the physical instances of the corresponding package.