in reply to read text table
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
|
|---|