- 论坛徽章:
- 7
|
for not
biru:- #!/usr/bin/perl
- sub X {
- map join( '_', split /\|/ ),
- glob '{' . join( '}{', map join( '|,', @$_ ) . '|', @_ ) . '}';
- }
- sub From {
- map { s/(\w+)/'$1',/g; s/\(/[/g; s/\)/],/g; eval } shift;
- }
- sub Extract {
- my ( $Op, @data ) = @{ +shift }[ 1, 0, 2 ];
- $Op eq 'not' ? map { ref $_ ? Extract($_) : $_ } $data[0]
- : $Op eq 'or' ? map { ref $_ ? Extract($_) : $_ } @data
- : X map { ref $_ ? [ Extract($_) ] : [$_] } @data;
- }
- my $String = <DATA>;
- my @Result = Extract From $String;
- print $_ . $/ for @Result;
- __DATA__
- (A interact ((B or C) or (((D inside E) or F) not inside G)))
复制代码 |
|