Here's a simple program to do what you have described. It is an overkill that it captures all data from the table. But you could do other things with the captured data I suppose. :-)
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---
The output is as required -
$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

In reply to Re: read text table by Roger
in thread read text table by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.