Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Falkkin is working on a Java Huffman encoder...

Moved only by the will to serve, I propose him an example of what he could do if he did that in Perl... :-)

$"=$/=$_;map{$0{$_}++}split//,$_=<>;@0=map{[$_,$0{$_},$_]}keys%0; $/=1+1;until(@0==1){@0=sort{$$b[1]<=>$$a[1]}@0;$t=pop@0;$p=pop@0; push@0,[[$$t[0],$$p[0]],$$t[1]+$$p[1],$$t[$/].$$p[$/]];map{map{$t {$_}=$;%$/.$t{$_}}split//;$;++}$$t[$/],$$p[$/]}s/(.)/$t{$1}/gs;sub _{my$t=pop;if(ref$t){my@t=map{if(!ref$$t[$_]){1,unpack"b8",$$t[$_]} else{0,""}}0,1;"@t[0,$/,1]"._($$t[0])._($$t[1])."$t[-1]"}}print pack"sB*",length,_($0[0][0]).$_

(This was one of my "helpers" for OPC5)
Corresponding Huffman decoder to be posted soon.

In reply to Huffman encoder by BooK

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2020-10-20 12:14 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (210 votes). Check out past polls.