in reply to read text table
The output is as required -use strict; use Data::Dumper; my @cols = qw/ BUS SERVICE DAY tm FROM DEPT TO ARR 24_7 /; my @table = (); my $capture; while (<DATA>) { chomp; $capture=1, next if (/Bus Timetable/); $capture=0, last if length($_) == 0 && $capture; if ($capture) { next if /^(?:\| BUS|\+)/; # ignore lines begin with + and BUS s/\|//g; # strip out | characters s/^\s+//g; # strip leading zero's my @rec = split /\s+/, $_; my %rec = map { $cols[$_] => $rec[$_] } 0 .. $#cols; push @table, \%rec; } } # debug print out print Dumper(\@table); # to print out from:to pairs foreach (@table) { printf "%s%s:%s%s\n", $_->{FROM}, $_->{DEPT}, $_->{TO}, $_->{ARR}; } __DATA__ ---TEXT BEFORE--- +-----------------+ | Train Timetable | +-----------------+--+------------+-----------+------+ | TRN SERVICE DAY tm | FROM DEPT | TO ARR | 24/7 | +--------------------+------------+-----------+------+ | T4 metro mon 15 | twn 0900 | Apt 1011 | yes | | T6 intl mon 45 | LDN 1000 | XTR 1426 | no | | T2 susx mon 20 | cly 1034 | btn 1118 | no | | T0 xxxxx xxx xx | xxx xxxx | xxx xxxx | xxx | +--------------------+------------+-----------+------+ +---------------+ | Bus Timetable | +---------------+----+------------+-----------+------+ | BUS SERVICE DAY tm | FROM DEPT | TO ARR | 24/7 | +--------------------+------------+-----------+------+ | C4 metro mon 15 | twn 0900 | Apt 1011 | yes | | C6 intl mon 45 | LDN 1000 | XTR 1426 | no | | B2 susx mon 20 | cly 1034 | btn 1118 | no | | A0 xxxxx xxx xx | xxx xxxx | xxx xxxx | xxx | +--------------------+------------+-----------+------+ ---TEXT AFTER---
$VAR1 = [ { 'DEPT' => '0900', 'FROM' => 'twn', 'ARR' => '1011', 'DAY' => 'mon', 'SERVICE' => 'metro', '24/7' => 'yes', 'tm' => '15', 'TO' => 'Apt', 'BUS' => 'C4' }, ... ... twn0900:Apt1011 LDN1000:XTR1426 cly1034:btn1118 xxxxxxx:xxxxxxx
|
|---|