aws-sdk-perl icon indicating copy to clipboard operation
aws-sdk-perl copied to clipboard

"unblessed reference" when accessing a result object

Open mpbro opened this issue 7 years ago • 3 comments

Hi, am a bit embarrassed to be posting this here, as this is very likely not a bug.

Here's a snippet of code, using similar syntax as your provided examples.

$res = $ec2->DescribeInstances();
p $res;
my $reservations = $res->Reservations;
p $reservations;
my $instances = $reservations->Instances;

The code dies on the final line. I can't access the "Instances" method of the Paws::EC2::Reservation object without (apparently) blessing the object reference $reservations. Exactly how would I bless $reservations in my code?

Thanks, Morgan

mpbro avatar Jul 02 '18 22:07 mpbro

Hi,

Please don’t be ashamed. This, at minimum, helps others that will have your same problem :)

The problem that you’re running into is that Reservations is an ArrayRef of reservation objects. To do something with it you can treat it as an array:

foreach my $r (@{ $res->Reservations }) {
  ...
}

The same will happen with the Instances on each $r (it’s an ArrayRef of instances)

Please tell us if the documentation mislead you in any way.

pplu avatar Jul 03 '18 06:07 pplu

Jose,

That worked just fine. Thank you very much for replying.

The Documentation did not mislead me. If you could just put the lines of code that you wrote into the example scripts, I'm sure you'll get fewer dumb questions. ;-)

I'm not a professional SW engineer; I'm actually a geophysicist who uses perl controllers to manage multi-day runs of number-crunching code (Fortran 90) on Linux nodes. I've been mildly proficient in perl for over a decade. I really appreciate you and your team putting this SDK together. Perl is a good and useful language, and I would rather continue to use perl than to port all my high-level code to the "language du jour".

Morgan

mpbro avatar Jul 03 '18 15:07 mpbro

@piratefinn, @glenveegee, @agimenez, @castaway, @karenetheridge, @ureesoriano, @ilmari, @BeerBikesBBQ, @kidambisrinivas, @Grinnz, @PopeFelix, @ioanrogers, @dtikhonov, @eduardbadillo, @brianhartsock, @rmp, @maneta, @juair10, @chorny, @arc, @stevecaldwell77, @mla, @shardiwal, @dnmfarrell, @manwar, @frioux, @meis, @jjatria, @autarch

This is for you guys 👍

pplu avatar Jul 04 '18 09:07 pplu