O munificent ones!
I've been working with binary strings, which, coming from an image file, can have any bin-value. The following behaviour caused a lot of head scratching till I found out where the problem was:
my @strings=("ab30ff","30","ab1a30"); for (@strings){ $_=pack ("H*",$_); } for my $b1 (@strings){ print "here: "; while ($b1){ my $b1=substr $b1,0,1,""; my $bits=unpack ("B*",$b1); print "$bits//"; } print "\n"; } here: 10101011//00110000//11111111// here: here: 10101011//00011010//
As you can see, if \x30 comes at the end of the string or the string only consists of \x30, "while" breaks off. The strings come from a read-in filehandle, which was in binmode, but have been extracted and passed between subs. Is there any way to force "while" to treat it as binary here.
All suggestions gratefully received

In reply to while loop on binary : \x30 by sphalaris

Title:
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, details, 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, summary, 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.