I tried to confirm that behavior with:
$str="asdkjhasdkjh".chr(0)."666"; print "\n$str\n"; print length($str)."\n"; print "yes" if $a = substr($str,12,1); print "\n$a\n";
But chr(0) is just results in a true. But if you mean ord(0) or chr(48), that evaluates as an integer, and thus false, and thusly ends your loop.

Prevent that with checking for the length of the string, instead of the true-ness ;) of it.

while( length my $a =substr $z,$g,1) {
should do it

Hope this helps,

Jeroen
"We are not alone"(FZ)
Update: Ponder how this runs:

$str="asdkjhasdkjh".chr(0)."or 0 and I am 666"; print "\n$str\n"; print length($str)."\n"; my $g=0; while( length( my $a= substr $str, $g, 1)){ print "Character nr $g reads $a\n"; $g++; } print "\n\n\tSecond run, without length\n"; $g=0; while( my $a= substr $str, $g, 1){ print "Character nr $g reads $a\n"; $g++; }
and I think that makes sense ;-} <code>

In reply to Re: Bad Char in string by jeroenes
in thread Bad Char in string by jepri

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.