develooper Front page | perl.perl6.internals | Postings from October 2001

substr broken?

Thread Next
From:
Brian Wheeler
Date:
October 16, 2001 09:53
Subject:
substr broken?
Message ID:
1003251920.4056.64.camel@wombat.educ.indiana.edu
I'm getting some weird results when using substr.  Here's my test
program:

	set	S0,"Hello world"
	print	"Arg to Reverse: "
	print	S0
	print	"\n"
	set	S1,""
	set	S2,""
	length	I0,S0
	dec	I0
$loop:	substr	S2,S0,I0,1
	print	"string so far:"
	print	S1
	print	", "
	print	S2
	print	"\n"
	concat	S1,S2
	dec	I0
	ge	I0,0,$loop
	set	S0,S1
	end


Here's the output:
Arg to Reverse: Hello world
string so far:d, d
string so far:l, l
string so far:r, r
string so far:o, o
string so far:w, w
string so far: ,  
string so far:o, o
string so far:l, l
string so far:l, l
string so far:e, e
string so far:H, H

Why is S1 set on the first iteration, before the concat?

Brian


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About