Christopher M Burger wrote:
> I was wondering if anyone had any ideas on how to parse a datafile
> with fixed length records but no carriage returns.  All records are
> on one line. There are 3 fields per record the first is 10 spaces,
> the second is 15 and the third is 40 then it starts back with 10
> again.

Hi Christopher.

If you set the input record separator variable to a number, it will do
fixed-length reads from the file. THen you can use 'unpack' to split
each record into its constituent fields. Try like this:

    $/ = 65;
    open FILE, "< file.dat" or die $!;
    while (<FILE>) {
        my ($field1, $field2, $field3) = unpack('a10a15a40', $_);
    }
    close FILE;

I've not tested this. I think it will be easier for you anyway since
you have appropriate data.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to