On Aug 10, Hamish Whittal said:

>I have an octet string that I need to print. When I print it, I get some
>rubbish on the screen. I would therefore like to translate this to
>something printable.
>
>e.g I have 110110101100010011111011 and I want to print this as 11011010
>1000100 11111011

You want to print it as sets of 8 bits?  There are many ways.  Here are
two:

  while ($output =~ /(.{8})/g) {
    print "$1 ";
  }

and

  my $len = length $output;
  my $i = 0;
  while ($i < $len) {
    print substr($output, 8 * $i++, 8), " ";
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to