This isn't very pretty, but it demonstrates the use of unpack to solve your problem:

#!/usr/bin/perl use strict; use warnings; my $template = 'x2A4A8A4A3x2A6A5x2A5A5x2A4'; my ($bus,$service,$day,$time,$from,$departure,$to,$arrival,$avail); while (<DATA>) { next if m/^\+/; next unless /^|/; ($bus,$service,$day,$time,$from,$departure,$to,$arrival,$avail +) = unpack($template,$_); next unless $bus =~ /[A-Z]\d/; print "Bus $bus of the $service service, arrives at $to at $ar +rival, from $from, leaving at $departure on $day. ($avail)\n"; } __DATA__ ---TEXT BEFORE--- +---------------+ | 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---

Output

Bus C4 of the metro service, arrives at Apt at 1011, from twn, leaving + at 0900 on mon. (yes) Bus C6 of the intl service, arrives at XTR at 1426, from LDN, leaving +at 1000 on mon. (no) Bus B2 of the susx service, arrives at btn at 1118, from cly, leaving +at 1034 on mon. (no) Bus A0 of the xxxxx service, arrives at xxx at xxxx, from xxx, leaving + at xxxx on xxx. (xxx)

You can find more information on unpack by doing perldoc -f unpack at your command line.

Hope that helps.

--
Allolex

Update 2003-10-20 15:46:09 CEST: This node inspired me to look at all of the options in perldoc -f pack and handle the delimiters as null bytes.

Perl and Linguistics
http://world.std.com/~swmcd/steven/perl/linguistics.html
http://www.linuxjournal.com/article.php?sid=3394
http://www.wall.org/~larry/keynote/keynote.html


In reply to Re: read text table by allolex
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.