Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 281913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:14:37+00:00 2026-05-12T05:14:37+00:00

What is the difference between package, module and class in object oriented Perl?

  • 0

What is the difference between package, module and class in object oriented Perl?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:14:38+00:00Added an answer on May 12, 2026 at 5:14 am

    Modules are a single file, a .pm file that provides code. That could be no packages, a single package, or more than one package. A module doesn’t really care what is in it, so it can be code that inserts itself into the same namespace, a more-traditional set of subroutines in a library or define Perl’s idea of a class.

    A package, also known as a namespace, contains its own variables and subroutines. It’s a way of segregating different parts of your program. You create the package and put your code into it:

    package SomePackage;
    
    sub some_subroutine { ... } # really SomePackage::some_subroutine
    

    You load the module to get access to the package:

    use SomePackage; # read and compile the module file
    
    SomePackage::some_subroutine( ... );
    

    A Perl class is a package and its associated behavior. The methods in a class are just normal subroutines, although when we treat the subroutines as methods, the first parameter is the thing (a package name or object, also known as the referent) that called method:

    package SomeClass;
    
    sub class_method { my( $class, @args ) = @_; ... }
    sub instance_method { my( $self, @args ) = @_; ... }
    

    Since the class is just a package like any other package and probably lives in a module, you access it the same way with use:

     use SomeClass;
    
     my $i = SomeClass->class_method( ... ); 
    

    The OO arrow syntax does some special stuff to let the some_method subroutine know that it’s being called as a method. Perl puts the referent (the SomeClass in this case) as the first argument. Additionally, when using the OO syntax, Perl knows to use its inheritance features.

    Methods called with ‘->’ get the referent as the first parameter to the method, so this call:

      SomeClass->new('world'); 
    

    is syntactically the same as if you had called it with the class name as the first parameter:

      SomeClass::new( 'SomeClass' ,'world'); # no inheritance this way
    

    That works the same for objects too. When an object is the referent:

    my $i = SomeClass->new(); 
    $i->bar( 'world'); 
    

    the object is the first parameter as the method:

    SomeClass::bar($i, 'world'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between package and object?
What's the difference between a module and package in Python? See also: What's the
what is the difference between something like package { public class Myclass { var
What's the difference between something being defined in the scala package object and in
What are the difference between a public class member class data { public: std::list<data>
Is there a difference between a package and a folder in eclipse? for example,
The difference between Add-In and Integration Package is still unclear and now with Visual
What is the difference between Scala traits Haskell type class and C++0x Concepts? Like
In Common Lisp package definition, what is the difference between (defpackage #:foo (:use :cl)
I would like to know What are the difference between folder-structure and package used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.