CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [rushadrena] Representing a connection matrix of graph: Edit Log



wickedxter
User

Aug 8, 2012, 4:27 PM


Views: 3548
Re: [rushadrena] Representing a connection matrix of graph

this works

Code
use strict; 
use warnings;

my %connections;


while (<DATA>){
my ($value1, $value2) = split(' ');

$connections{$value1} = [] if ! defined $connections{$value1};

push (@{$connections{$value1}},$value2);

}


for my $keys (keys %connections){
print "$keys : ";
for my $array (@{$connections{$keys}}){
print "$array";
}
print "\n";
}


__DATA__
a b
c d
a d
c a
f g
f h


OUTPUTS:


Code
c : da 
a : bd
f : gh



(This post was edited by wickedxter on Aug 8, 2012, 4:27 PM)


Edit Log:
Post edited by wickedxter (User) on Aug 8, 2012, 4:27 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives