
BillKSmith
Veteran
Aug 11, 2012, 8:34 PM
Post #17 of 18
(7865 views)
|
Re: [rushadrena] Representing a connection matrix of graph
[In reply to]
|
Can't Post
|
|
Laurent is certainly right. Your requirements are hopelessly inconsistent from one post to the next. I have answered a nearly identical post in the perl monks forum. This suggests that either this is a school assignment or you have no interest in learning perl, but want someone to do your work for you. If this is not true, I suggest that you post a complete working package, including your perl code, all referenced data files, instructions for running it, and the exact output expected. We will be able to run it, examine the output, and help you correct the code. Your post #15 is a step in the right direction, but I am not sure what code you are using or exactly what is wrong. I do not see any need for either @array or @con. I would parse the arguments with a regular expression, and store the data directly in the hash. Note: Your sample data is used if no arguments are provided.
# 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 strict; use warnings; @ARGV = ('a,b|c', 'c,d|e', 'a,d|e') unless @ARGV; my %HoA; foreach ( @ARGV ) { m/^([a-z])[,]([a-z])[|]([a-z])$/ ; push @{$HoA{$1}}, $2; } print "\n===========\@HoA=====\n"; print "from->to\n"; while (my ($key, $values) = each %HoA) { print $key, "=> [", join(',', @$values), "]\n"; } SAMPLE_OUTPUT (default data) =========HOA======= from->to c=> [d] a=> [b,d] Good Luck, Bill
(This post was edited by BillKSmith on Aug 11, 2012, 8:58 PM)
|