Perl Autovivication Use case -


i came across piece of code (modified excerpt):

 $respmap;  $respidarray;  foreach $respid (@$somelist) {       push(@$respidarray, $respid);  }  $respmap->{'ids'} = $respidarray;  return $respmap; 

is there reason use autovivication in case? why not do

 $respmap;  @respidarray;  foreach $respid (@$somelist) {       push(@respidarray, $respid);  }  $respmap->{'ids'} = \@respidarray;  return $respmap; 

follow up: give me use case of autovivication?

either way correct; first 1 using array reference $respidarray, , second plain array @respidarray. you'll need array references when building complex data structures (check perldoc perlreftut), other it's 1 you'll choose.

note in both cases you're assigning array reference $respmap->{'ids'}, examples pretty similar.

and btw, autovivification thing , has dynamic creation of data structures.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -