Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Re: Compressing a set of integers

by BrowserUk (Patriarch)
on Jan 27, 2003 at 05:39 UTC ( [id://230133]=note: print w/replies, xml ) Need Help??

in reply to Compressing a set of integers - Solution
in thread Compressing a set of integers

I'd seen, but never really taken any notice of the 'w' format for pack & unpack. Totally made for the job.

Perhaps the only downside of using 'w' instead of 'S' or 'L' is that you need to unpack the whole string to get to an individual value. With 'S' or 'L' you could have indexed into the string with substr to read or write an individual value. How much of a penalty this is will depend on your application and whether you will always need to access all the values in any given string each time.

Probably worth it if the savings on space are enough.

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re: Re: Re: Compressing a set of integers
by pfaut (Priest) on Jan 27, 2003 at 13:34 UTC

    It wouldn't be necessary to use substr to extract a value in a buffer full of packed shorts or longs. The '@' code can be used to move to a specific offset in the buffer before extracting.

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://230133]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-05-28 06:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found