in reply to Bad Char in string

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>

Replies are listed 'Best First'.
Re: Re: Bad Char in string
by jepri (Parson) on Apr 19, 2001 at 15:13 UTC
    I gave it a go, but perl wouldn't run until I changed your line to:

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

    I'm afraid it didn't work^H^H^H^H fix the problem.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.