in reply to
Problem printing/storing hash
The values in @con are array references, not strings. They cannot be split.
The values in %HoA are array references. They must be dereferenced before printing.
# 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; # replaced by wksmith
my ($key, $value) = @$_;
push @{$HoA{$key}}, $value;
}
# PRINTING THE HASH
foreach (keys %HoA) {
#print "$_ => $HoA{$_}\n"; #replaced by wksmith
print "$_ => @{$HoA{$_}}\n";
}
Note: Entries may be printed out of order.