in reply to Re: file parsing help
in thread file parsing help

Well that is a definately a sexier approach. Seems like it is much more flexible and more robust than mine.
As for the Kim records, that was a cut and paste mistake.

I appreciate the code, I will take it and tweak it a bit and see what happens.

What's going on here?
@temp = unpack 'xa5x2a3x2a15x2a6x2a5x2a5x4a5x9a8x4a9x5a5x15a5x4a9', $line;

Replies are listed 'Best First'.
Re^3: file parsing help
by BrowserUk (Patriarch) on Nov 13, 2006 at 22:25 UTC

    Take a look at the docs for unpack (also pack as it carries more information).

    Briefly, the format template 'xa5x2a3x2a15x2a6x2a5x2a5x4a5x9a8x4a9x5a5x15a5x4a9', consists of 2 types of format specifier.

    1. 'x' & 'xN', which skips forward over 1 or more characters.

      Used here to skip over the inter-column whitespace.

    2. 'aN', which 'captures' N characters.

      This is used to extract the fixed format fields.

    The results are assigned into the array @temp. Note that the length specifiers I've used are quickly approximated from the example posted, you will want to review the values carefully in the light of your full data.

    Unlike a regex capture, what is in the bytes captured is irrelevant, it is based entirely upon the character positions (like substr). I've attempted to show how the parsing works below, but the stupid wrap 'feature' of PM means it doesn't really work.

    < 0> <1> < 2 > < 3 > < 4 > < 5 > < 6 > xaaaaaxxaaaxxaaaaaaaaaaaaaaaxxaaaaaaxxaaaaaxxaaaaaxxxxaaaaaxxxxxxxxx 0 CDE, DEBORAH M. AAF103 FJB1A FTB5A 3.0 < 7 > < 8 > < 9 > <10 > < 11 > aaaaaaaaxxxxaaaaaaaaaxxxxxaaaaaxxxxxxxxxxxxxxxaaaaaxxxxaaaaaaaaa .02 107.83 3.0 .02 107.83

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Cool approach, I will look into it further and try to fine tune it to the actual data set. Thanks for the pointers.
Re^3: file parsing help
by planetscape (Chancellor) on Nov 13, 2006 at 22:53 UTC