- 论坛徽章:
- 5
|
这个问题引起了大家的极大兴趣。
觉得很不错,受益匪浅,谢谢!
我的理解 ~ {:2_172:}- my ( $V1, @data, %dup );
- while (<DATA>) {
- my ( undef, undef, $col3, $col4 ) = split;
- next if grep { /^\.$/ } $col3, $col4;
- my @elem = split /;/, $col3;
- my @exists;
- for my $e (@elem) {
- my ( $K, $v, $v2 ) = split /[\[\],-]/, $e;
- if ( $dup{$K}++ ) {
- push @exists, (0) x ( $v2 ? $v2 - $v + 1 : 1 );
- next;
- }
- $V1 ||= ( $v || 1 );
- if ($v2) {
- my $V2 = $V1 + $v2 - $v;
- push @exists, map { $V1 + $_ } 0 .. $v2 - $v;
- push @{ $data[0] }, "${K}[$V1,$V2]";
- $V1 = $V2 + 1;
- }
- else {
- push @{ $data[0] }, "${K}[$V1]";
- push @exists, $V1++;
- }
- }
- @elem = split /;/, $col4;
- for my $i ( 0 .. $#exists ) {
- next unless $exists[$i];
- my ($k) = $elem[$i] =~ /(\w+)$/;
- push @{ $data[1] }, "[$exists[$i]]$k";
- }
- }
- print "@$_\n" for @data;
- __DATA__
- a b s[1];p[2] [1]d;[2]t
- b c s[1];q[2]; [1]d;[2]y;
- a d c[1,3]; [1]e;[2]t;[3]b;
- b d p[1];y[2] [1]d;[2]y2;
- e f abb hhh
- g n . 1
- f n 6[1-4] [1]e;[2]t;[3]b2;[4]h;
- a d c[1,3];A[4]; [1]e;[2]t;[3]b;[4]d; # ADD
复制代码 回复 1# huang6894
|
|