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 69353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:33:36+00:00 2026-05-10T19:33:36+00:00

How do I apply ‘use base’ in Perl to inherit subs from some base

  • 0

How do I apply ‘use base’ in Perl to inherit subs from some base module?

I’m used to C++ inheritance mechanics, and all the sites I googled for this caused more confusion then help. I want to do something like the following:

#! /usr/bin/perl #The base class to inherit from use strict; use warnings;  package 'TestBase';  #------------------------------- sub tbSub {     my ($self, $parm) = @_;     print '\nTestBase: $parm\n'; }  1; 

.

#! /usr/bin/perl #The descendent class use strict; use warnings;  use base qw(TestBase); sub main; sub mySub;  #------------------------------- #Entry point... main();  #---code------------------------ sub main {     mySub(1);     tbSub(2);     mySub(3); }  #------------------------------- sub mySub {     my $parm = shift;     print '\nTester: $parm\n'; } 

Perl complains/cannot find tbSub.

  • 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. 2026-05-10T19:33:37+00:00Added an answer on May 10, 2026 at 7:33 pm

    The C++ mechnics aren’t much different than the Perl mechanics: To use inheritance, you need two classes: the base class and the inheriting class. But you don’t have any descendent class.

    You are also lacking a constructor. Unlike C++, Perl will not provide a default constructor for you.

    Your base class contains a bad syntax error, so I guess you didn’t try the code before posting.

    Finally, as tsee already observed, you will have to let Perl know whether you want a function call or a method call.

    What you really want would look something like this:

    my $foo = TestDescendent->new(); $foo->main();   package TestBase;  sub new {    my $class = shift;    return bless {}, $class; }  sub tbSub {    my ($self, $parm) = @_;    print '\nTestBase: $parm\n'; }  package TestDescendent; use base 'TestBase';  sub main {     my $self = shift;     $self->mySub( 1 );     $self->tbSub( 2 );     $self->mySub( 3 ); }  sub mySub {     my $self = shift;     my $parm = shift;     print '\nTester: $parm\n'; }  1; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As a die-hard RESTafarian I'd say use HTTP (the REST… May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer timeIntervalSince1970 returns an NSTimeInterval, which is a typedef for double;… May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer Without seeing how $auth is defined in Authentication.php, it's hard… May 11, 2026 at 6:30 pm

Related Questions

How do I apply the MarshalAsAttribute to the return type of the code below?
How do I apply 'use base' in Perl to inherit subs from some base
How do I apply a repeating texture that always maintains its original scale (1
how do i apply the the distinct keyword in mysql so that it is
How do I apply a change to text in an element without losing its

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.