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.

Perl is the programming world's equivalent of English

In reply to Re: help :) by GrandFather
in thread help :) by Harry_Sor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.