in reply to Re: Multidimentioal array
in thread Multidimentioal array
Hi Monk::Thomas ... I was fooling with these and got a strange result when passing a non-integer to the scripts.
[05:32][nick:~/dev/perl_dev/test/monks]$ cat 1133944.pl #!/usr/bin/env perl use strict; use warnings; print " Enter dimension : "; my $n = <STDIN>; my $k=1; my @matrix; for(my $i = 0; $i < $n; $i++) { for(my $j = 0; $j < $n; $j++) { $matrix[$i][$j]= $k++; } } print " the matrix : \n\n"; for(my $i = 0; $i < $n; $i++) { for(my $j = 0; $j < $n; $j++) { print "$matrix[$i][$j] "; } print "\n"; }
[05:31][nick:~/dev/perl_dev/test/monks]$ perl 1133944.pl Enter dimension : 3.14159 the matrix : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[05:32][nick:~/dev/perl_dev/test/monks]$ cat 1133944-2.pl #!/usr/bin/env perl use strict; use warnings; print " Enter dimension : "; my $n = <STDIN>; $n--; my $k = 1; my @matrix; for my $i (0..$n) { for my $j (0..$n) { $matrix[$i][$j]= $k++; } } print " the matrix : \n\n"; for my $i (0..$n) { for my $j (0..$n) { print "$matrix[$i][$j] "; } print "\n"; }
[05:33][nick:~/dev/perl_dev/test/monks]$ perl 1133944-2.pl Enter dimension : 3.14159 the matrix : 1 2 3 4 5 6 7 8 9
Interesting that the number should be rounded differently in those two scripts!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Multidimentioal array
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 | |
|
Re^3: Multidimentioal array
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 |