Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm generating random 32 bit integers based on Math::Random::MTwist. I want to pipe the raw binary output, but (obviously) print() won't do. Neither will syswrite() to STDOUT.

Am I missing something simple?

Replies are listed 'Best First'.
Re: Need Raw Binary Output
by Anonymous Monk on Dec 05, 2016 at 21:01 UTC

    See pack:

    print pack('N',123456789); # unsigned, big-endian # output (hex): 07 5b cd 15 print pack('V',123456789); # unsigned, little-endian # output (hex): 15 cd 5b 07

      Yep! Looks like just what I needed. And simple, as I suspected (and hoped).

      Thank you for the help.