Subhrangshu Das has asked for the wisdom of the Perl Monks concerning the following question:
I was trying to write the program of magic square. So I need a dynamic 2D array. But however when I tried to put some number in the array, it behaves abnormally. the output shows the first 2 rows as identical... my code was...
################################################### #!/usr/bin/perl use warnings; print " Enter dimension : "; my $n = <STDIN>; my $i=0; my $j=0; my $k=1; my @matrix = ( $n , $n ); for($i = 0; $i < $n; $i++) { print " see how the first row changes automatically...\n\n"; for($j = 0; $j < $n; $j++) { $matrix[$i][$j]= $k++; print "row = $i and col = $j input = $matrix[$i][$j] firstrow $j = $m +atrix[0][$j] //for error checking \n"; } } print " the matrix : \n\n"; for($i = 0; $i < $n; $i++) { for($j = 0; $j < $n; $j++) { print "$matrix[$i][$j] "; } print "\n"; } ############################################
just check it out
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multidimentioal array
by Monk::Thomas (Friar) on Jul 09, 2015 at 12:08 UTC | |
by 1nickt (Canon) on Jul 09, 2015 at 12:37 UTC | |
by roboticus (Chancellor) on Jul 09, 2015 at 12:53 UTC | |
by 1nickt (Canon) on Jul 09, 2015 at 15:27 UTC | |
by roboticus (Chancellor) on Jul 09, 2015 at 21:42 UTC | |
by Monk::Thomas (Friar) on Jul 10, 2015 at 08:55 UTC | |
by 1nickt (Canon) on Jul 10, 2015 at 11:22 UTC | |
by Monk::Thomas (Friar) on Jul 10, 2015 at 11:37 UTC | |
by Subhrangshu Das (Initiate) on Jul 10, 2015 at 07:55 UTC | |
|
Re: Multidimentioal array
by ambrus (Abbot) on Jul 09, 2015 at 12:57 UTC | |
|
Re: Multidimentioal array
by 1nickt (Canon) on Jul 09, 2015 at 12:13 UTC | |
by Subhrangshu Das (Initiate) on Jul 10, 2015 at 07:53 UTC | |
by Monk::Thomas (Friar) on Jul 10, 2015 at 09:05 UTC |