Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numerical vs String variable

Status
Not open for further replies.

wim1

IS-IT--Management
Oct 2, 2000
3
0
0
US
I have an initial file I read in. It is just a bunch of zeroes. Max will be 400, looking like this.
0
0
0
0
0

If a certain event occurs, I want to increment that postition by 1. Instead, my output looks like this
0
0
10
0
0

It appears to me it treats it aas a string and not as a number. How do I fix this?

# Here is my code to open the file
open(ASKED, "$asked_data");
@asked = <ASKED>;
close(ASKED);


# Needless to say there is a lot of other code inbetween, but here is where I ask my question. If it is true, I want the corresponding postion in the array given by $sequence to increase the number in $asked by one, i.e if is 0 become 1, if it is 1 become 2, etc..

if ($form{&quot;$sequence[$i]&quot;} eq $answers[$sequence[$i]] || $tick == 1) {
$correct++;
$num=$asked[$sequence[$i]];
$num++;
$asked[$sequence[$i]]=$num;
}
}

# The last thing I do is write it to a file

open(ASKED, &quot;>$asked_data&quot;);
print ASKED @asked;
close(ASKED);

Thanks
Wim Libby
libbys@camalott.com

[sig][/sig]
 
Well, despite not wanting to provoke further personal cries for help... I do already get enough email, thank you... I'll answer anyway. Guess I'm too nice for my own good ;)

Try this:

$num=int($asked[$sequence[$i]]); [sig]<p> Sincerely,<br><a href=mailto: > </a><br><a href= Anderson</a><br>CEO, Order amid Chaos, Inc.<br>
[/sig]
 
Tom,

I do appreciate your help, but that did not fix it. I still get
0
10
0
instead of
0
1
0
in my output file. Any other suggestions? If not, I do appreciate your time.

Wim [sig][/sig]
 
<grin> that mist be it Tom.. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
<grin> that must be it Tom.. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
Come to think of it, the original method you used should work just fine. Are you sure that the 0 after the 1 isn't the one that belongs below that line?

Try this:

print ASKED &quot;^@asked^&quot;;

If you get carrots (^) between the 1 and 0 then it is the method of storage that is the problem. Try stripping all newlines and converting into a string first. [sig]<p> Sincerely,<br><a href=mailto: > </a><br><a href= Anderson</a><br>CEO, Order amid Chaos, Inc.<br>
[/sig]
 
Tom,

Thanks for the suggestions. Your last one made me try something and it worked!!!! Here is what I did:

if ($form{&quot;$sequence[$i]&quot;} eq $answers[$sequence[$i]] || $tick == 1) {
$correct++;
$num = $asked[$sequence[$i]];
$num++;
$asked[$sequence[$i]] = &quot;$num\n&quot;;

Thanks again!!
Wim libby [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top