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

  • Home
  • SEARCH
  • 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 891617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:55:08+00:00 2026-05-15T13:55:08+00:00

I am doing a Perl OO example (mainly to reacquaint myself with Perl) and

  • 0

I am doing a Perl OO example (mainly to reacquaint myself with Perl) and using
inheritance, it seems that the SUPER works in the subclass when calling the superclass constructor and that
the superclass variables don’t bind to the subclass object. Why would this be?

################################################
## Package : Person                          ##
################################################
package Person;

################################################
## Constructor                                ##
################################################
sub new(){

    my $class = shift;
    my $data = {};
    $data->{'firstName'} = shift;
    $data->{'secondName'} = shift;  
    bless $data, $class; 
    #bless $data, "Person"; #hack
    return $data;
}

################################################
## Getter Methods                            ##
################################################

sub getFirstName(){
  my $data = shift;
  return $data->{'firstName'};
}

sub getSecondName(){
  my $data = shift;
  return $data->{'secondName'};
}

################################################
## Setter methods                            ##
################################################

sub setFirstName($){
  my $data = shift;
  $data->{'firstName'} = shift;
}

sub setSecondName($){
  my $data = shift;
  $data->{'secondName'} = shift;
}

################################################
## Other Methods                              ##
################################################

sub printall(){
    my $data = shift;
    $\ = "\n";
    print "FirstName: ". $data->{'firstName'} ."\n";
    print "SecondName: ". $data->{'secondName'} ."\n";
}
1;

################################################
## Package : Coder                            ##
################################################

package Coder;
@ISA = qw( Person );
use strict;
use warnings;

################################################
## Constructor                                ##
################################################
sub new {
    my $class = shift;
    my $self = {};

    bless $self, $class;
    my $superFirstName = shift;
    my $superSecondName = shift;

    print "new superfirstname "  .$superFirstName;
    print "new supersecondname " .$superSecondName; 

    $self->{'language'} = shift; #i.e. Java 
    $self->{'experience'} = shift;  #number of years

    #$self = $self->SUPER::new($superFirstName, $superSecondName); 
    Person->new($superFirstName, $superSecondName);
    return $self;
}

################################################
## Getter Methods                            ##
################################################

sub getLanguage(){
  my $data = shift;
  return $data->{'language'};
}

sub getExperience(){
  my $data = shift;
  return $data->{'experience'};
}

################################################
## Setter methods                            ##
################################################

sub setLanguage($){
  my $data = shift;
  $data->{'language'} = shift;
}

sub setExperience($){
  my $data = shift;
  $data->{'experience'} = shift;
}

################################################
## Other Methods                              ##
################################################

sub printall(){
    my $data = shift;
    $\ = "\n";

    print "Experience: " . $data->{'experience'};
    print "Language: " . $data->{'language'};

    $data->SUPER::printall();

}
1;


################################################
## Package : Main                            ##
################################################
package main;

my $developer = Coder->new("John","Smith","Perl","2");

$developer->printall();
  • 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-15T13:55:08+00:00Added an answer on May 15, 2026 at 1:55 pm

    It’s because you are not doing anything with the Person->new return. So it just creates a whole other Person object, and Coder skates off happily.

    What you want to do is

    my $self = $class->SUPER::new( $superFirstName, $superSecondName );
    

    And have Person bless it into whatever class you pass it–as it does. Then after creating $self the SUPER way, you want to add to it the fields you need.

    So it should look something like:

    use strict;
    use warnings;
    
    sub new {
        my $class = shift;
        my $superFirstName = shift;
        my $superSecondName = shift;
        print "new superfirstname "  .$superFirstName;
        print "new supersecondname " .$superSecondName; 
    
        my $self = $class->SUPER::new( $superFirstName, $superSecondName );
        # OR
        # $self = $class->Person::new( $superFirstName, $superSecondName );
    
        $self->{language}   = shift; #i.e. Java 
        $self->{experience} = shift;  #number of years
    
        return $self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Replacing the Special Character using Perl while i am doing this . I got
I know a great thing about perl is that there's multiple ways of doing
Doing an ajax get request works as expected using the following code: $.ajax({ type:
I'm looking for an example of redirecting stdout to a file using Perl. I'm
Okay, so I'm using perl to read in a file that contains some general
Ok this is what I'm doing. I'm making a perl interpreter for documents that
What is the recommended way of doing date arithmetics in Perl? Say for example
I learning Perl and doing a home made project to my family (a subscription
I have php scripts that call perl scripts to do various things and sometimes
I'm a perl programmer doing a bit of C#. Facing an odd issue with

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.