[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Variable issue substr
From: |
Aharon Robbins |
Subject: |
Re: [bug-gawk] Variable issue substr |
Date: |
Thu, 14 May 2015 13:57:08 +0300 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hello.
Thank for the note. Please send plain text emails in the future instead
of HTML.
You are running into problems converting from string to number.
Here is a corrected version of your second program:
BEGIN {
a = "2345"
b = "6789"
a1 = substr(a, length(a), 1)
b1 = substr(b, length(b), 1)
print a1, b1
for (i = a1 + 0; i <= b1 + 0; i++) {
print i
}
}
Note the addition of zero to both a1 and b1 in order to force numeric
comparison. Otherwise, i is converted from string to number and back to
string each time around the loop, producing the results that you saw.
Thanks,
Arnold