Thread Progress 4GL: Beautifier, Regex (2 answers)
Opened by TEngelke at 2007-08-28 17:03

bloonix
 2007-08-28 17:37
#98779 #98779
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use strict;
use warnings;

my %ho = ( 
    '/*' => sub { ++$_[0] },
    '*/' => sub { --$_[0] },
);

while ( my $line = <DATA> ) { 
    my $c; 
    for ( $line =~ /(\/\*|\*\/)/g ) { 
        $c = $ho{$_}($c);
        warn "error in line $.! closing comment that isnt open\n" if $c < 0;
    }   
    warn "error in line $.! open comment isnt closed\n" if $c; 
}

__END__
korrekte zeile /* Dies ist ein Test */
define variable abc as character. /* Dies ist ein Test /* */
CODE /* KOMMENTAR /* KOMMENTAR2 */
KOMMENTAR */ CODE /* KOMMENTAR2

#> ./test.pl
error in line 2! open comment isnt closed
error in line 3! open comment isnt closed
error in line 4! closing comment that isnt open


geht bestimmt noch besser... aber nur ein Beispiel...
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Progress 4GL: Beautifier, Regex