in reply to Compressing a string, but leaving it as a string
I couldn't resist. This is a 8bit <-> 7bit conversion utility so only ASCII 0 - 127 is supported.
With a reduction of 12.5%, I doubt you really want to use it though.#!/usr/bin/perl use strict; use warnings; my $foo = compress( join '', 'a' .. 'z' ); print length $foo, "\n"; print grow( $foo ); sub compress {pack'b*',join'',map{sprintf'%b',ord}split//,pop} sub grow {join'',map{chr oct"0b$_"}grep$_,split/(.{7})/,join'',map{vec +"@_",$_,1}0..length("@_")*8-1}
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compressing a string, but leaving it as a string
by Anonymous Monk on Feb 17, 2011 at 14:56 UTC | |
by Limbic~Region (Chancellor) on Feb 17, 2011 at 18:26 UTC |