zing has asked for the wisdom of the Perl Monks concerning the following question:
# 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; $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 "\n==========connections======\n"; print "from->to\n"; print " @$_\n" for @con; my %HoA; foreach (@con) { ($key, $value) = split; push @{$HoA{$key}}, $value; } # PRINTING THE HASH foreach (keys %HoA) { print "$_ => $HoA{$_}\n"; }
======OUTPUT======
xguest@localhost Downloads$ perl code.pl 'a,b|c' 'c,d|e' 'a,d|e'
a b c
c d e
a d e
==========connections======
from->to
a b
c d
a d
ARRAY(0x95a5fd4) :
ARRAY(0x95a6014) :
ARRAY(0x95a6134) :
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem printing/storing hash
by roboticus (Chancellor) on Aug 10, 2012 at 12:39 UTC | |
|
Re: Problem printing/storing hash
by Marshall (Canon) on Aug 10, 2012 at 13:04 UTC | |
|
Re: Problem printing/storing hash
by BillKSmith (Monsignor) on Aug 10, 2012 at 14:45 UTC |