title: Dereference perl array of objects after pass to function
body: <p>I'm weird with dereferencing objects.</p>
  <p>In my prog <em>oobjtest</em> I want to get a list of objects.</p>
  <p>Steps: in perl testprog <em>oobjtest</em>
  1)
  Call a class method <em>my @lo_hashref_objects = oclass::getemall();</em>.
  Print them.</p>
  <p>Steps: in perl class <em>oclass</em></p>
  <ol>
  <li>call another class method to get filecontent</li>
  <li>content-lines store after split in an array <em>my @lol</em> by reference</li>
  <li>pass this array to function <em>getemall</em> by <em>return @lol</em>. List-data are reachable by <em>$array_ref-&gt;[$i]</em></li>
  <li>Create a new object <em>my $self = oclass-&gt;new;</em>. Put data in instance variables by Setter functions.</li>
  <li>Objects work, see Getter function output.</li>
  <li>Store objects in an array. Data of objects available via $self as well as via array addressing, see <em>getemall</em></li>
  <li>Pass it to testprog <em>oobjtest</em></li>
  <li>Getting data out of list <em>my @lol</em> fails. Lack of syntax knowledge, but I cannot solve it.</li>
  </ol>
  <p>The class file</p>
  <pre><code>    package oclass;
  
      use warnings;
      use strict;
      use Carp;
      # to make your class data a file-scoped lexical
      my $Census = 0;
  
      use feature qw/say switch/;
      use lib qw(/home/hj/lib/perl/oo/test);
      our $verb_file = '/home/hj/lib/perl/oo/test/data/verb.txt';
      #-----------------------------------------------------------
      sub new 
      {
          my $class = shift;
          my $self = {};
      
          $self-&gt;{bez} = undef;
          $self-&gt;{etym} = undef;
  
          # &quot;private&quot; data
          $self-&gt;{&quot;_CENSUS&quot;} = \$Census;
  
          bless ($self, $class);
          ++ ${ $self-&gt;{&quot;_CENSUS&quot;} };
          return $self;
      }
  
  
      # class method
      sub _get_file_content
      {
          my ($class_name) = @_;
          open my $fh, &quot;&lt;:encoding(UTF-8)&quot;, $verb_file or die;
          my @lol = ();
          while (&lt;$fh&gt;) {
              chomp;
              # gather lines per reference in list lol
              push @lol, [ split ' &amp; ' ];   
          }
          close $fh or croak &quot;Couldn't close '$verb_file': $Carp::OS_ERROR&quot;;  
          for my $array_ref ( @lol ) {
              print &quot;DEBUG _get_file_content: lol\t  @$array_ref , \n&quot;;
              for (my $i = 0; $i &lt;= $#$array_ref; $i++) {
                  say &quot;$i: &quot;, $array_ref-&gt;[$i];
              }
          }
          return @lol;   
      } # end _get_file_content
  
  
      sub getemall
      {
          my @lol = ();
          my @lo_hashref_objects = ();
          @lol = oclass::_get_file_content();
  
          for my $array_ref ( @lol ) {
              print &quot;getemall: lol\t  @$array_ref , \n&quot;;
              for (my $i = 0; $i &lt;= $#$array_ref; $i++) {
                  say &quot;$i: &quot;, $array_ref-&gt;[$i];
              }
          }
      
          my $i = 0;
          for my $array_ref ( @lol ) {
              my $self = oclass-&gt;new;
              $self-&gt;setbez($array_ref-&gt;[0]);
              $self-&gt;setetym($array_ref-&gt;[1]);
              say $self-&gt;getbez;
              say $self-&gt;getetym;
      
              push @lo_hashref_objects, $self;
      
              print &quot;getemall:CCC&quot;, $lo_hashref_objects[$i]-&gt;getbez, &quot; \n&quot;;
              print &quot;getemakk: C1C1C1: &quot;, $lo_hashref_objects[$i]-&gt;getetym, &quot; \n&quot;;
              $i++;
          }
  
          return @lo_hashref_objects;
      } # end getemall
  
      #-----------------------------------------------------------
      sub getbez {
          my $self = shift;
          return $self-&gt;{bez};
      }
      sub setbez {
          my ($self, $bez) = @_;
              croak('Usage: $self-&gt;setbez($bez)') if @_ &lt; 2;
              $self-&gt;{bez}= $bez;
          return;
      }
  
      sub setetym {
          my $self = shift;
          if (@_) { @{ $self-&gt;{etym} } = @_ }
          return @{ $self-&gt;{etym} };
      }   
      sub getetym {
          my $self = shift;
          return @{ $self-&gt;{etym} };
      }
  
      1; # so the require or use succeeds
  </code></pre>
  <p>Testprogram</p>
  <pre><code>    #!/usr/bin/perl
      #
      use warnings;
      use strict;
      use Carp;
  
      use lib qw(/home/hj/lib/perl/oo/test);
  
      use oclass;
  
      ### call the class method &quot;getemall&quot; to gather all the single lines in  file (data)
      my @lo_hashref_objects = oclass::getemall();
      my $i=0;
      for my $obj_ref ( @lo_hashref_objects ) {
          print &quot; \nafter call of getemall: $obj_ref \n&quot;;
          print &quot;after call of getemall: $obj_ref-&gt;getbez \n&quot;;
          print &quot;ref obj_ref: &quot;, ref($obj_ref), &quot;\n&quot;;
          print &quot;after call of getemall: $obj_ref \n&quot;;
          print &quot;afterlo_hashref_object: $lo_hashref_objects[$i++]-&gt;getbez \n&quot;;
  
          print &quot;after call of getemall: $obj_ref-&gt;getetym \n&quot;;
      }
  </code></pre>
  <p>Output partially</p>
  <pre><code>     der
      Versuch
      getemall:CCC der 
      getemakk: C1C1C1: Versuch 
      die
      Verbindung
      getemall:CCC die 
      getemakk: C1C1C1: Verbindung 
  
      after call of getemall: oclass=HASH(0x55f70e320278) 
      after call of getemall: oclass=HASH(0x55f70e320278)-&gt;getbez 
      ref obj_ref: oclass
      after call of getemall: oclass=HASH(0x55f70e320278) 
      afterlo_hashref_object: oclass=HASH(0x55f70e320278)-&gt;getbez 
      
      hj@debian:~$ 
  </code></pre>