Leser: 24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#!/usr/bin/perl -w # ___40 # | | # 20|___| use strict; my ($i, $ii, %matrix, %asd); #test $i=0; %asd=($i => {$i => " "}); print $asd{0}{0}; #klappt wunderbar #test #initialisierung %matrix for ($i=0;$i<20;$i++) { for ($ii=0;$ii<40;$ii++) { %matrix=($i => { $ii => "X"}); } } print $matrix{0}{1}; #klappt nicht main(); sub main { for (;;) #main { print (" Matrix\n"); print ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); for ($i=0;$i < 20;$i++ ) { print ("x"); for ($ii=0;$ii < 40;$ii++) { print $asd{0}{0}; #klappt auch wunderbar #print $matrix{1}{1}; klappte auch nicht } print ("x\n"); } print ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); sleep(1); } }
%matrix=($i => { $ii => "X"});
1 2 3 4 5 6 7 8 9 10 11 12
use Data::Dumper; #initialisierung %matrix for ($i=0;$i<20;$i++) { for ($ii=0;$ii<40;$ii++) { %matrix=($i => { $ii => "X"}); print Dumper \%matrix; } } print $matrix{0}{1}; #klappt nicht
$matrix{$i} = { $ii => "X" };
1 2 3 4 5 6 7 8 9
#initialisierung @matrix my @matrix; for my $first_dim ( 0 .. 19 ) { for my $second_dim ( 0 .. 39 ) { $matrix[$first_dim]->[$second_dim] = "X"; } } print $matrix[0]->[1];
$matrix{$i}{$ii} = " ";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use strict; use warnings; my $x=7; my $y=10; # kurze variante: #my @array=map{[map{'W'}(1..$y)]}(1..$x); # auführlicher: my @array; for my $px (0..$x-1) { for my $py (0..$y-1) { $array[$px][$py]='W'; } } # hüpsche Ausgabe printf(" %s\n +-%s\n", join('',map{sprintf("%02u ",$_)}(1..$y)),'---'x$y); printf("%02u | %s\n |\n", $_+1, join('',map{sprintf("% 2s ",$_)}@{$array[$_]}) ) for(0..$#array);
2010-10-01T01:55:40 hannesPRCode (perl): (dl )1 2 3 4 5 6 7 8 9... for ($i=0;$i<20;$i++) { for ($ii=0;$ii<40;$ii++) { %matrix=($i => { $ii => "X"}); } } ...
1
2
3
4
5
6
7
8
9
10
11
12
13
$ perl -MData::Dumper -e 'for ($i=0;$i<20;$i++)
> {
> for ($ii=0;$ii<40;$ii++)
> {
> %matrix=($i => { $ii => "X"});
> }
> }
> print Dumper \%matrix'
$VAR1 = {
'19' => {
'39' => 'X'
}
};
1 2 3 4 5 6 7
@arr=map {[$_ .. $_+39]} (0..19); for( $i=0; $i<@arr; $i++ ) { for( $j=0; $j<@{$arr[$i]}; $j++ ) { printf "%02d, ", $arr[$i]->[$j]; } print "\n"; }
1 2
@arr=map {[$_ .. $_+39]} (0..19); print join("\n", map { my $l=$_; join(", ", map { sprintf "%02d", $_ } @$l) } @arr), "\n";
1 2
@arr=map {[$_ .. $_+39]} (0..19); printf +("%02d, " x @$_)."\n", @$_ for @arr