in reply to Bad Char in string
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.$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";
Prevent that with checking for the length of the string, instead of the true-ness ;) of it.
should do itwhile( length my $a =substr $z,$g,1) {
Hope this helps,
Jeroen
"We are not alone"(FZ)
Update: Ponder how this runs:
and I think that makes sense ;-} <code>$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++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Bad Char in string
by jepri (Parson) on Apr 19, 2001 at 15:13 UTC |