Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Problem printing/storing hash

by BillKSmith (Curate)
on Aug 10, 2012 at 14:45 UTC ( #986760=note: print w/ replies, xml ) Need Help??

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 '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.

Comment on Re: Problem printing/storing hash
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986760]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-11-25 07:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (672 votes), past polls