Suppose I have a line with both text and numbers in it. Maybe it looks like this:
word 15 word word 20
If I split the line this way:
($a,$b,$c,$d,$e) = split
I find I can use $b and $e as numbers-- do math on them and stuff.
But--
I have a slightly messier line. Instead of 15 I have 15,000 and instead of 20, it's 20,000. I assign it as an array thus:
@line = split
And now, though $line[1] and $line[4] print out as 15,000 and 20,000, when I try to do any math on them I get an error, that 15,000 or 20,000 isn't a numeric in line whatever.
The question I was going to ask is-- is this something to do with assigning this as an array instead of scalars, but I just stumbled across that answer. I see it's the commas in the variables in the second case causing the problem.
So, new question-- how can I best manipulate $line[1] etc to get rid of the comma? I don't want to change the line I'm splitting because I'm using it later and the comma needs to be there then. I'm having trouble knowing how to think about the string once it's been assigned to a variable. Or, whether I'm even thinking about this the right way at all. ;)
ps this isn't homework. I'm teaching myself trying to solve some simple problems at work, and until I crashed into this I was doing pretty well. We all gotta start somewhere.
Thanks,
NovMonk
In reply to changing a string to a numeric variable by NovMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |