in reply to read text table

Hi, ctilmes, i have tried your code and it works great for the table i have given but maybe i should have said that the entries in the table can be of any length, so the destinations can be town instead of twn and the time is sometime 9am instead of 0900. Could you also explain the regulars expressions you have used as i dont understand them too well

Thank you for your replies, Kwun

Replies are listed 'Best First'.
Re: Re: read text table
by ctilmes (Vicar) on Oct 20, 2003 at 11:37 UTC
    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:
      Thanks thats excellent

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