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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:02:28+00:00 2026-06-18T05:02:28+00:00

I have one object that has an attribute of an array of another group

  • 0

I have one object that has an attribute of an array of another group of objects. I have a toString method that I want to print out the entire contents of the objects. The main goal is to have the Job object call all the post process jobs that are in the array. I want to call the method toString on the objects in the object array as well. Currently, I’m getting this error:

Can't call method "toString" without a package or object reference at JobClass.pm line 52, <JOBFILE> line 5. (which is $item->toString(); in the foreach loop)

Dumper on $item shows the following:

$VAR1 = bless( {
             'ImportID' => '22',
             'ImportTableID' => '1234',
             'ImportTable' => 'testImport'
           }, 'PostJob' );

Main goal of what I’m trying to understand is how I can call a method on an object returned from an member array.

Classes instantiated this way:


    my $postJob = PostJob->new(ImportTable => "testImport",ImportTableID => "1234", ImportID => "22");
    my @postJobs ="";
    push (@postJobs,$postJob);
    $postJob->toString(); #this works fine
    my $job = Job->new(DirectoryName => "testDir",StagingTableName => "stageTable", QBStagingTableID => "5678",postProcessJobs => \@postJobs); 
    $job->toString(); #Breaks with error above

Code is below:


    package PostJob;
    use Moose;
    use strict;
    use Data::Dumper;

    has 'ImportTable' => (isa => 'Str', is => 'rw', required => 1);
    has 'ImportTableID' => (isa => 'Str', is => 'rw', required => 1);
    has 'ImportID' => (isa => 'Str', is => 'rw', required => 1);

    sub toString {
     # Print all the values 
     my $self = shift;;
    print "Table Name for Post Job is ".$self->ImportTable."\n";
    print "Table ID for Post Job is ".$self->ImportTableID."\n";
    print "Import ID for Post Job is ".$self->ImportID."\n";
    }

    package Job;

    use strict;
    use Data::Dumper;
    use Moose;

    has 'DirectoryName' => (isa => 'Str', is => 'rw', required => 1);
    has 'StagingTableName' => (isa => 'Str', is => 'rw', required => 1);
    has 'StagingTableID' => (isa => 'Str', is => 'rw', required => 1);
    has 'postProcessJobs'=> (isa => 'ArrayRef', is => 'rw', required => 0);


    sub addPostJob {
     my ($self,$postJob) = @_;
     push(@{$self->postProcessJobs()},$postJob);

    }

    sub toString 
     {
     # Print all the values.
     my $self = shift;
     print "DUMPING JOB OBJECT CONTENTS*****************************\n";
     print "Directory is ".$self->DirectoryName."\n";
     print "Staging Table is ".$self->StagingTableName."\n";
     print "Staging Table ID is ".$self->StagingTableID."\n";

        print "DUMPING POST JOB CONTENTS*****************************\n";   
        foreach my $item (@{$self->postProcessJobs()})
            {

                $item->toString();
                print Dumper($item);
            }
        print "END DUMPING JOBS*****************************\n";    
    }


    1;

  • 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-06-18T05:02:30+00:00Added an answer on June 18, 2026 at 5:02 am

    The problem is on the following line:

    my @postJobs ="";
    

    This creates the first member of the array, but this member is not a job, it is an empty string. Replace it with

    my @postJobs;
    

    and the error goes away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an single-dimensional array of PHP objects. Each object has two attributes, one
I have an object called Document that has a one-to-many relationship with DocumentPersonCc. I
I have one very general object that I want to map to a destination
I have a controller method that returns a jSON object and in one calling
I have two arrays. If an object in one array has no matching email
I have an array of object names. These objects are HTML elements. I want
Lets say that I have one component which is doing something with Workbook object
I have a current Date object that needs to be incremented by one day
Given a case where I have an object that may be in one or
I have a class that contains objects of two other classes. I need one

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.