Re: handling flat-file layouts -- pack or sprintf or something else?
On Thu, May 24, 2001 at 10:58:38PM -0400, Stephen P. Potter wrote: > Lightning flashed, thunder crashed and chris brown <[EMAIL PROTECTED]> whispered: > | I would prefer to write each record using pack, but I > | can't see how to elegantly get pack to zero-fill > | without using sprintf. And I kind of feel like once > | I'm using sprintf I might as well ONLY use sprintf for > | the whole record. And *that* doesn't feel very > | Perlish to me, so I suspect there's a different > | solution. > > Nope, pack works on bytes. If you want to pad your output, you need to use > something like sprintf. See perlfunc: What exactly feels "unperlish" about sprintf? Perl is all about using the right tool for the right job, and sprintf imho is the right tool for zero-filling. If you insist on doing it without sprintf, there are some alternatives in perlfaq4. Walt
Re: handling flat-file layouts -- pack or sprintf or something else?
Lightning flashed, thunder crashed and chris brown <[EMAIL PROTECTED]> whispered: | I would prefer to write each record using pack, but I | can't see how to elegantly get pack to zero-fill | without using sprintf. And I kind of feel like once | I'm using sprintf I might as well ONLY use sprintf for | the whole record. And *that* doesn't feel very | Perlish to me, so I suspect there's a different | solution. Nope, pack works on bytes. If you want to pad your output, you need to use something like sprintf. See perlfunc: ยท You must yourself do any alignment or padding by inserting for example enough `'x''es while packing. There is no way to pack() and unpack() could know where the bytes are going to or coming from. Therefore `pack' (and `unpack') handle their output and input as flat sequences of bytes. -spp