in reply to help :)
Without data we can't tell what's happening. I've cleaned up your code somewhat and added a DATA section to it. You should add data to the DATA section that demonstrates the problem. You'll need to tell us what you expect to see compared to what you do see.
use strict; use warnings; my %red; print "Indica el numero de nodos\n"; chomp (my $nodos = <DATA>); #aqui se declara la matriz una vez que se sabe el numero de nodos print "Introduzca las conecciones de los nodos.\n"; for my $n (0 .. $nodos - 1) { for my $i (0 .. $nodos - 1) { if ($n != $i) { chomp ($red{$n}{$i} = <DATA>); } } } for my $n (0 .. $nodos - 1) { my $aristas = 0; for my $i (0 .. $nodos - 1) { next if $n == $i; ++$aristas if $red{$n}{$i} == 1; } print <<MSG; la posicion del nodo en escala vector, numero de aristas y coeficiente + de clustering respectivamente: $n aristas: '$aristas' MSG if ($aristas == 1 || $aristas == 0) { print "0\n"; next; } my $areales = 0; for my $j (0 .. $nodos - 1) { next if $n == $j; for my $l (0 .. $nodos - 1) { next if $j == $l || $l == $n; $areales++ if $red{$j}{$l} == 1; } } $areales = $areales / 2; my $clust = (2 * $areales) / ($aristas * ($aristas - 1)); print "clust: $clust"; } __DATA__ 2 1 0 0 1
With the data given the code above prints:
Indica el numero de nodos Introduzca las conecciones de los nodos. la posicion del nodo en escala vector, numero de aristas y coeficiente + de clustering respectivamente: 0 aristas: '1' 0 la posicion del nodo en escala vector, numero de aristas y coeficiente + de clustering respectivamente: 1 aristas: '0' 0
but I've no idea if that is what you expect or not. As a general thing, using a DATA section like this can make testing your code much easier.
Note that I removed all the variable declarations at the start of the program and declared variables where they are first needed. I also used Perl loops instead of C loops and used early exits from loops to avoid needless nesting - that helps make the code easier to understand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help :)
by Harry_Sor (Initiate) on Dec 02, 2014 at 01:42 UTC | |
by GrandFather (Saint) on Dec 02, 2014 at 03:23 UTC |