Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Posts
    74

    Unanswered: Reading from a fixed position text file in Perl

    Hi!

    I have a fixed-position text file and I want to read positions 94 through 103 of each record.
    Overall I should be able to:
    1. Remove first two lines of header
    2. Remove last two lines of trailer
    3. Pick out positions 94 through 103 for all the records and get the value in those positions
    How can I accomplish this in a Perl program?

    Thanks for your help.

    -PV

  2. #2
    Join Date
    Nov 2002
    Posts
    207
    Use substr function to cut data from string.

    substr($LineFromFile,93,10);

    HTH.

  3. #3
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Code:
    #!\user\bin\perl -w
    open(DATA,'<'.shift) or die "$!";
    my(@a_Lines)=(<DATA>);
    close(DATA);
    chomp(@a_Lines);
    foreach (1,2) {
      pop(@a_Lines); shift(@a_Lines);
       };
    foreach (@a_Lines) {
      $_=substr($_,93,10);
       };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •