in reply to Re: Converting Binary Numbers into Binary File
in thread Converting Binary Numbers into Binary File

BEGIN block, then -

perl -pe 'BEGIN{binmode STDOUT}$_=pack"B*",-+-$_'

- 38 chars :-)

<update>oops, wrong - that one strips leading zeroes.. oh, wait...

perl -pe 'BEGIN{binmode STDOUT}chomp;$_=pack"B*",$_'
</update>

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^3: Converting Binary Numbers into Binary File
by ikegami (Patriarch) on Sep 13, 2006 at 17:22 UTC

    I'll beat your 41
    perl -pe 'BEGIN{binmode STDOUT}chomp;$_=pack"B*",$_'
    with 36
    perl -pe 'BEGIN{binmode STDOUT}$_=pack"B16",$_'

      15 for me ;-)
      perl -C0 -pe '$_=pack"B16",$_'
      Boris
        Oookay - as perl golf rules, you add some switches up front: these count.

        And in what way your STDOUT is guaranteed binmode here? hmm?

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

      Take this:
      perl -e 'binmode STDOUT;print pack"(B16)*",<>'

      36, but without -p :-)

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}