in reply to beginner's question regarding objects

How the internal structure of the object is organised shouldn't influence how it's indexed. If you later changed the object to
bless $class, [ @_ ];

you still want to index it the same way. So, either use the individual accessors:

$e->index( index => $index, type => $type, id => $id, body => { head => $object->head, opinion => $object->opinion, result => $object->result, }, );

or, create a method for the object to dump a structure to index:

sub hashify { my $self = shift; return { %$self } }

which you can later (after converting to the array implementation) change to

my @attributes = qw( head opinion result ); sub hashify { my $self = shift; return { map { $attributes[$_] => $self->[$_] } 0 .. $#$self } }

Update: Note that hashify creates a shallow copy, i.e. it doesn't clone nested references.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: beginner's question regarding objects
by McSvenster (Novice) on Mar 28, 2015 at 13:44 UTC

    Thanks a lot for this explanation! I forgot that i could build a method for this into my model...

    As my object can get lots of accessors I was looking for a lazy - sorry, I ment efficient - way. Your "hashify" is exactly what I was looking for.

    Happy coding weekend

    MCS