S
Stan Horwitz
I am working on a perl program where I extract a variable from a line of
input and I want to keep a running count of that variable. I am using
the substr function to extract the variable. For purposes of example,
let's say the extracted variable is called $extracted_variable and my
total variable is called $total. The $extracted_variable comes from
something along the lines of $extracted_variable = substr($stuff, 0, 8);
$total = $total + $extracted_variable;
Let's say $total is initialized to a value of 10 and
$extracted_variable is "900".
I want the result to be 910. I do not want a result of 90010.
How do I do that? My current attempts all result in errors such as
isn't numeric in addition (+) at
and after spending an hour querying books on perl and googling, I am
getting nowhere.
I am sure this is a simple matter, but what's the trick? Do I have to
convert each element in the string to a number? I thought perl just did
that on the fly.
input and I want to keep a running count of that variable. I am using
the substr function to extract the variable. For purposes of example,
let's say the extracted variable is called $extracted_variable and my
total variable is called $total. The $extracted_variable comes from
something along the lines of $extracted_variable = substr($stuff, 0, 8);
$total = $total + $extracted_variable;
Let's say $total is initialized to a value of 10 and
$extracted_variable is "900".
I want the result to be 910. I do not want a result of 90010.
How do I do that? My current attempts all result in errors such as
isn't numeric in addition (+) at
and after spending an hour querying books on perl and googling, I am
getting nowhere.
I am sure this is a simple matter, but what's the trick? Do I have to
convert each element in the string to a number? I thought perl just did
that on the fly.