Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Problem printing/storing hash

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986760]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-12-14 19:52 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (408 votes). Check out past polls.