I made some minor mods. I would suggest that you enable strict; (you will have to do some work to get it so that it doesn't complain).
Update: Possible recoding below...
#!/usr/bin/perl -w #use strict; #### I would recommend you do this!!! # Takes input in the form 'a,b|c' # How to run : perl code.pl 'a,b|c' 'c,d|e' 'a,d|e' # Outputs a NX3 for the above input data. # Outputs connections in Nx2 form use Data::Dumper; print "@ARGV\n"; $arg=join(' ',@ARGV); @det=split //, $arg; for ($i=0; $i <=8; $i++) {$trip[$i]=$det[2*$i];} my @array; while (@trip) { push(@array, [ splice(@trip, 0, 3) ]); } print "@$_\n" for @array; for ($i=0; $i <=2; $i++) { for ($j=0; $j <=1; $j++) { $con[$i][$j]=$array[$i][$j];} } print Dumper \@con; #### use the Dumper! print "\n==========connections======\n"; print "from->to\n"; print " @$_\n" for @con; my %HoA; foreach my $rowref (@con) { #each @con is a ref to row ($key, $value) = @$rowref; push @{$HoA{$key}}, $value; } # PRINTING THE HASH foreach (keys %HoA) { print "$_ => @{$HoA{$_}}\n"; #was missing a curly pair } __END__ C:\TEMP>perl hasharray.pl "a,b|c" "c,d|e" "a,d|e" a,b|c c,d|e a,d|e a b c c d e a d e $VAR1 = [ [ 'a', 'b' ], [ 'c', 'd' ], [ 'a', 'd' ] ]; ==========connections====== from->to a b c d a d c => d a => b d
Update:

Maybe I'm missing something but this seems to be overly complex. Maybe this is all that is needed?

#!/usr/bin/perl -w use strict; # Takes input in the form 'a,b|c' # How to run : perl code.pl 'a,b|c' 'c,d|e' 'a,d|e' # Outputs a NX3 for the above input data. # Outputs connections in Nx2 form use Data::Dumper; print "Input args are: @ARGV\n"; my %hash; foreach my $input (@ARGV) { my($key, $value ) = ($input =~ m/\w/g)[0,1]; #not sure what role if any the |c or |e plays in this? push @{$hash{$key}}, $value; } print Dumper \%hash; __END__ C:\TEMP>perl hasharray2.pl "a,b|c" "c,d|e" "a,d|e" Input args are: a,b|c c,d|e a,d|e $VAR1 = { 'c' => [ 'd' ], 'a' => [ 'b', 'd' ] };

In reply to Re: Problem printing/storing hash by Marshall
in thread Problem printing/storing hash by zing

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.