develooper Front page | perl.perl6.language | Postings from September 2000

Re: pack/unpack is damn unperlish. Explain them as Perl.

Thread Previous | Thread Next
From:
Sam Tregar
Date:
September 18, 2000 12:41
Subject:
Re: pack/unpack is damn unperlish. Explain them as Perl.
Message ID:
Pine.LNX.4.21.0009181540260.7211-100000@airtrout.tregar.com
On Mon, 18 Sep 2000, Michael G Schwern wrote:

> On Mon, Sep 18, 2000 at 12:32:08PM -0400, Sam Tregar wrote:
> 
> If I grok'd the bastards, I'd write the explaination myself.

If you grok'd the bastards I bet you'd realize how useless such an
explanation would be.  The chief reason for using pack/unpack is to deal
with external binary formats.  Why would you want a description that
didn't talk about external binary formats?

> > Maybe you don't get to know how good it is until you need it?
> 
> I'm sure there are many times when pack should have been used but it
> got hacked together with something else.  The prime example is
> fixed-width data parsing.  Most people reach for substr() or a regex,
> but the best solution (as pointed out in perlfaq5) is pack.  Yet it
> still remains obtuse and I'm largely cargo-culting when I use it.

I think you're talking about unpack() here, which I've only used once.  I
think unpack() is usually replaceable by substr() or regexes.  Contrast
that with pack() for which no equivalent replacement is possible, as far
as I know.

-sam



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About