in reply to Re: read text table
in thread read text table

If you want 4 character towns, change the unpack line to this:
my ($from, $dept, $to, $arr) = unpack('x23a4x2a4x3a4x1a4', $_);
unpack is different from regular expressions. The xn skips over characters, the an captures the character string:
x23: skip 23 characters a4: get 4 characters x2: skip 2 a4: get 4 ...
The 4 a4 unpack directives capture the 4 parts of the string you are interested in. Add this to strip the extra spaces:
s/\s+//g for ($from, $dept, $to, $arr);
Here's the whole thing:
#!/usr/bin/perl use warnings; use strict; do { $_ = <> } until /Bus Timetable/; <> for (1..3); # skip titles 3 lines while (<>) { last if /^\+/; my ($from, $dept, $to, $arr) = unpack('x23a4x2a4x3a4x1a4', $_); s/\s+//g for ($from, $dept, $to, $arr); print "$from$dept:$to$arr\n"; }

Replies are listed 'Best First'.
Re: Re: Re: read text table
by Anonymous Monk on Oct 20, 2003 at 12:17 UTC
    Thanks thats excellent

    Thanks to everyone else who has replied also, you've helped me a lot