skullbowl has asked for the wisdom of the Perl Monks concerning the following question:

I am running a analysis program that reads in data in the following manner;

input sno$ 1-3 school$ 5 class 6-7 Religion 9 education 15 Race 21 @23 (A1-A100) (1.); rename A1=Q11; rename A9=Q12; rename A28=Q13; rename A13=Q14;
The books and FAQ of Perl did not touch much abt defining fixed columns variable. How do I call in my variables in Perl? Thanks alot.
use Text::Soundex; print soundex ("Skullbowl");
RESULT : S414

edited 2001-05-11 by mirod: changed the title

Replies are listed 'Best First'.
Re: Reading Fixed Width Records.
by frankus (Priest) on May 10, 2001 at 14:15 UTC

    Book:
    Data Munging With Perl!!! By Dave Cross (davorg), it has a section on this (Chapter 7 - Fixed Width and Binary Data)
    (it has a section on most stuff, it's nice).

    Pedantry:

    • Please clarify what you want to achieve in english, and use the code to support this.
    • Please change your title, there are many ways to read data, how about "Reading fixed width fields"?
    Off the Cuff:
    Use regular expressions specifically @fields = m/(.{$width})/g; (as on page 129 of Data Munging With Perl)

    --

    Brother Frankus.

    ¤

      Thanks for the feedback & suggestion. I didn't know my english was not english. Basically i have a data file with fixed width fields and i am trying to read in these data. Will try to find the book that u mentioned. Btw, how does one change the title of a Root Node?
      use Text::Soundex; print soundex ("Skullbowl");
      RESULT : S414
Re: Reading in Data
by Masem (Monsignor) on May 10, 2001 at 15:12 UTC
    Assuming that this is correct:
    input sno$ 1-3 school$ 5 class 6-7 Religion 9 education 15 Race 21 @23 + (A1-A100) (1.);
    That is, everything separated by spaces, you can grab it all in one go using split on the space character (' '). That will give you an array of data such as :
    @array = ( 'input', 'sno$', '1-3', ... );
    You then process the individual data fields in whatever way you feel best.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain