in reply to Help to slurp records - $/ maybe?

IMHO, simpler is better - stick with the iterative approach as it will be much easier for you and anyone else who looks at the code to understand and maintain it 6 months or a year from now when it needs to be changed.

What you don't want to do is create some obfuscated code that takes someone a day to understand an another day to fix. Make it as simple as possible for *any* Perl person to understand.

HTH.

Replies are listed 'Best First'.
Re: Re: Help to slurp records - $/ maybe?
by Limbic~Region (Chancellor) on May 02, 2003 at 13:44 UTC
    hmerrill,
    IMHO, it is much simpler to have $/ = ""; than it is to have labels, redo statements, and variable flags.

    Cheers - L~R

      If $/ = ""; works, great. But it won't for the problem as you stated.

      What happens when someone needs to insert a 'Field 2b' in the format six months down the road? You would have to fully rewrite a grok-at-once gimmick, but you'd only have to add the support for a new field type if it were a sensible loop.

      --
      [ e d @ h a l l e y . c c ]

        halley,
        I am not sure I understand what you are saying. I realize that $/ = ""; doesn't work for my problem. I was just illustrating that it was a lot easier and was hoping to find a similar easy solution.

        As far as having to insert fields - that's not a problem. The record delimeter is and always will be the same thing. What is in between doesn't matter. The problem is that I can't see anything between the end of one record and the start of the next that can be used as a delimiter.

        L~R

      Debatable - I do conceed that the iterative approach means more code, keeping track of flags, etc. - it's not pretty. But I'd have to see a finished slurp example setting $/ = "" before judging that to be the better option. In all likelihood the slurp example may indeed come out on top, but its ease of understanding and maintainability would be greatly enhanced by a generous comment spelling out exactly what the thing does. Whatever you decide on as the final winner, post in this thread.