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: [wickedxter] Representing a connection matrix of graph: Edit Log



rushadrena
Novice

Aug 9, 2012, 2:38 AM


Views: 3650
Re: [wickedxter] Representing a connection matrix of graph

This is what I have written : -


Code
# 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;


Now do you know how to modify the above code so that it would read the input data(in the same format as presented in comments section) from a text file (each in a new line).
Actually I want to represent the Nx2 output which is :::
==========connections======
from->to
a b
c d
a d


For the above output I want this representation ::::

Code
%connections=(a=>[b,d],c=>[d]);



(This post was edited by rushadrena on Aug 9, 2012, 5:08 AM)


Edit Log:
Post edited by rushadrena (Novice) on Aug 9, 2012, 5:08 AM


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

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