- 论坛徽章:
- 307
|
- #!/usr/bin/perl
- use strict;
- use warnings;
- sub Display{
- my $ra = shift;
- foreach my $name (@{$ra->[0]}){
- print join ("\t", $name, $_), "\n" for @{$ra->[-1]};
- }
- }
- my ($last_pos, $raData) = (0, []);
- while (<DATA>){
- my $pos = 0;
- $pos = 1 if (/\A(\w+)\W+(.*)/ and $1 ne 'Name');
- if ($last_pos and !$pos){
- Display ($raData);
- $raData = [];
- }
- push (@{$raData->[$pos]}, $2);
- $last_pos = $pos;
- }
- Display ($raData);
- __DATA__
- Name: name1 id-1
- Name: name2 id-1
- Attr: attr1
- Attr: attr2
- Name: name3 id-1
- Name: name4 id-2
- Name: name5 id-2
- Name: name6 id-1
- Attr: attr3
- Attr: attr4
复制代码 |
|