Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Problem printing/storing hash

by BillKSmith (Deacon)
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 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.


Comment on Re: Problem printing/storing hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (17)
As of 2015-07-06 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls