A little different approach using a two-dimensional array...
# using two dimensional array # assumes sequence of records is always N...E...U... use strict; use warnings; my @station; my $row = -1; my $col = 0; print "STATION\tN\tE\tU\n"; while (<DATA>) { if ($_ =~ /^(\w\w+)\s+..*$/) { $col = 0; $station[++$row][$col] = $1; } elsif ($_ =~ /^[N|E|U]\s+(\d+)$/) { $station[$row][++$col] = $1; } } for(my $i = 0; $i <= $row; $i++) { for(my $j = 0; $j <= $col; $j++) { if($j > 0) { print "\t"; } print"$station[$i][$j]"; } print "\n"; } __DATA__ GRAZ X 4 Y 6 Z 3 N 22 E 3 U 15 KIGB X 2 Y 6 Z 6 N 13 E 20 U 11
Output:
STATION N E U GRAZ 22 3 15 KIGB 13 20 11
In reply to Re: Extract data from next n-th line
by dineed
in thread Extract data from next n-th line
by kana
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |