1 2 3 4 5 6 7 8
my $x = 0; my $c; while ( 1 ) { $c = ReadKey 0; last if $c !~ /^[0-9]$/; $x = 10 * $x + $c; } return -1 if $c ne ';';
1 2 3 4 5 6 7 8
my $c = ReadKey 0; my $x = ''; while ( 1 ) { last if $c !~ /^[0-9]$/; $x .= $c; $c = ReadKey 0; } return -1 if $c ne ';';
2013-05-23T11:06:59 MuffiDu kannst dein 2. Beispiel so umbaun, dass die Bedingung gleich im while steht.
2013-05-23T11:59:18 Kuerbis2013-05-23T11:06:59 MuffiDu kannst dein 2. Beispiel so umbaun, dass die Bedingung gleich im while steht.
Daran habe ich auch gedacht, aber mir kommt vor, dass ich so leichter erkennen kann, was vorsichgeht.
1 2 3 4 5 6 7 8 9 10 11 12 13
my $c; my $x = ''; while ( ( $c = ReadKey 0 ) =~ m/^[0-9]$/ ) { $x .= $c; } my $y = ''; while ( ( $c = ReadKey 0 ) =~ m/^[0-9]$/ ) { $y .= $c; } my $z = ''; while ( ( $c = ReadKey 0 ) =~ m/^[0-9]$/ ) { $z .= $c; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my $x = ''; my $c1; while ( ( $c1 = ReadKey 0 ) =~ m/^[0-9]$/ ) { $x .= $c1; } my $y = ''; my $c2 while ( ( $c2 = ReadKey 0 ) =~ m/^[0-9]$/ ) { $y .= $c2; } my $z = ''; my $c3 while ( ( $c3 = ReadKey 0 ) =~ m/^[0-9]$/ ) { $z .= $c3; }
1 2 3 4 5 6
my %inputs = (); for my $index ('input1', 'input2', 'input3') { while ( (my $char = ReadKey 0 ) =~ m/^[0-9]$/ ) { $inputs{$index} .= $char; } }
2013-05-24T07:30:09 KuerbisIst es in so einem Fall üblich, die variable $c immer wieder zu verwenden oder sollte man jedes mal eine neue deklarieren?