http://www.perlmonks.org?node_id=1047368

gaurav has asked for the wisdom of the Perl Monks concerning the following question:

Hi!! ,I have one query regarding Array-Autovivification & Hash-Autovivification . Please go through the below codes<\p>

Code for Array-Aut

my %provisions; my $person; while (<>) { if (/^(\S.*)/) { # a person's name (no leading whitespace) $person = $1; } elsif (/^\s+(\S.*)/) { # a provision die 'No person yet!' unless defined $person; push @{ $provisions{$person} }, $1; } else { die "I don't understand: $_"; } }

Code for Hash

my %total_bytes; while (<>) { my ($source, $destination, $bytes) = split; $total_bytes{$source}{$destination} += $bytes; } for my $source (sort keys %total_bytes) { for my $destination (sort keys %{ $total_bytes{$source} }) { print "$source => $destination:", " $total_bytes{$source}{$destination} bytes\n"; } print "\n"; }

Now my query is that how Perl will go for array autovivification & hash autovivification in respective codes

for your purpose ,I am also given you the input files for the respective codes

for Array

The Skipper blue_shirt hat jacket preserver sunscreen Professor sunscreen water_bottle slide_rule Gilligan red_shirt hat lucky_socks water_bottle The Skipper sextant

for hash

professor.hut skipper.crew.hut 8655 ginger.girl.hut laser3.copyroom.hut 6404 skipper.crew.hut fileserver.copyroom.hut 8534 gilligan.crew.hut skipper.crew.hut 1004 laser3.copyroom.hut ginger.girl.hut 4366 maryann.girl.hut professor.hut 8454 skipper.crew.hut professor.hut 7475 gilligan.crew.hut maryann.girl.hut 8128 gilligan.crew.hut maryann.girl.hut 5277 gilligan.crew.hut fileserver.copyroom.hut 6117 skipper.crew.hut professor.hut 5101 gilligan.crew.hut gilligan.crew.hut 9973 ginger.girl.hut fileserver.copyroom.hut 1448 skipper.crew.hut gilligan.crew.hut 2146 fileserver.copyroom.hut gilligan.crew.hut 9568 maryann.girl.hut laser3.copyroom.hut 8024 fileserver.copyroom.hut laser3.copyroom.hut 9574

please explain it to me ,that how perl has been identified that it has to go for Array or Hash Autovivification?