in reply to Unpack or substr to create CSV?

... a better choice ...

Here's the standard <rant>: What the heck is your criterion for "better"? I would gravitate to an unpack solution for fixed-width records, but might your maintainer better understand substr? If so, substr would be better. Are you concerned about speed? For such a small dataset, I doubt there would be any significant difference between the three approaches mentioned so far in this thread, but the only way to tell is to Benchmark. (Update: Do you want to support data validation at all?) And so on... </rant>


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^2: Unpack or substr to create CSV?
by Laurent_R (Canon) on May 02, 2015 at 18:59 UTC
    I agree with AnomalousMonk, for such a small dataset, any approach is probably good enough. Just use the one you understand best and that your maintainer is likely to understand best. I personally would choose substr because anytime I use unpack, I need to go through the documentation again, and substr is marginally better than a regex. But a regex would do just about as well for this data size.

    Je suis Charlie.

      After posting the above, I realized that a regex approach might give you data validation, if this was of any concern, almost for free, so I think now that I might incline in this direction. But again, there are too many unstated conditions and requirements to allow more than a hand-waving consideration of alternatives, although this may be valuable to johnmck.


      Give a man a fish:  <%-(-(-(-<

        Yes, ++. If validation comes for free (or almost) and is useful, then a regex is very likely to be a much better solution. Neither substr nor unpack will offer that.

        Je suis Charlie.