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?


In reply to Autovivification identification by gaurav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.