Thread perl-6.de: Deutsprachige Seite zum Thema Perl 6 (9 answers)
Opened by moritz at 2007-05-11 17:57

Froschpopo
 2007-05-19 16:56
#39115 #39115
User since
2003-08-15
2653 Artikel
BenutzerIn
[default_avatar]
Quelle: http://perl-6.de/

Code: (dl )
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
use v6;

my $fn = $*PROGRAM_NAME;

my $file = open($fn) err die "Can't read file '$fn': $!";
my %braces = ( '(' => ')',
'{' => '}',
'[' => ']',
);
my @stack;

for =$file -> my $line {
for ($line.comb(m/<[()\[\]\{\}]>/)) -> my $match {
if %braces{$match} {
# öffnende Klammer gefunden
push @stack, ~$match;
} else {
# schliessende Klammer gefunden
my $expected = %braces{pop @stack};
if $expected ne $match {
die "File '$fn' is not balanced: expected '" ~
$expected ~ "', found '$match'\n";
}
}
}
}


$file.close;

if @stack.elems == 0 {
say "File $fn is balanced";
} else {
say "File $fn is not balanced, more opening braces than closing ones";
}

da muss man ja ganz schön umdenken!\n\n

<!--EDIT|Froschpopo|1179579404-->

View full thread perl-6.de: Deutsprachige Seite zum Thema Perl 6