Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Your code looks roughly correct for the behavior you are expecting.

Some minor changes:

  • The second chomp call should be removed.
  • added Data::Dumper to inspect to dump output
  • attached $key lexical to a smaller scope
  • add error checking to file open
  • close filehandle when done reading it
  • lexical filehandle $IN1 rather than global filehandle IN1
#!/usr/bin/perl use strict; use warnings; use open IN => ':utf8'; use open OUT => ':utf8'; use Encode; use Data::Dumper; my $file1 = shift; my %hash; open( my $IN1, "<:encoding(utf8)", $file1 ) or die; while (<$IN1>) { chomp; my ($video, $p) = split /\t/; push( @{$hash{$video}}, $p ); #print "array of hash of $video <==== $p\n"; } close $IN1; foreach my $key ( keys %hash ) { print "$key: @{ $hash{$key} }\n" } print Dumper \%hash;
output:
mv89psg6zh4: A bird in a sink keeps getting under the running water fr +om a fauc et. A bird is bathing in a sink. A bird is splashing around under a ru +nning fau cet. A bird is bathing in a sink. A bird is standing in a sink drinkin +g water t hat is pouring out of the facet. A faucet is running while a bird stan +ds in the sink below. A bird is playing in a sink with running water. + A bird is playing in tap water. A bird is bathing in the sink. A bir +d is taking a bath. $VAR1 = { 'mv89psg6zh4' => [ 'A bird in a sink keeps getting under the r +unning water from a faucet.', 'A bird is bathing in a sink.', 'A bird is splashing around under a running + faucet.', 'A bird is bathing in a sink.', 'A bird is standing in a sink drinking wate +r that is pouring out of the facet.', 'A faucet is running while a bird stands in + the sink below.', 'A bird is playing in a sink with running w +ater.', 'A bird is playing in tap water.', 'A bird is bathing in the sink.', 'A bird is taking a bath.' ] };

In reply to Re: hash of arrays by spazm
in thread hash of arrays by Anonymous Monk

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [hippo]: Modularity is not the Apple way.

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2018-07-23 10:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (463 votes). Check out past polls.

      Notices?