in reply to numbers in parentheses not considered numeric values??
It's telling you that the string value "(49)" isn't numeric. Whenever you use a string as a number, perl tries to convert the string to a number using some simple rules. Usually it works just the way you want, but it can't possibly always do what you want.
Consider these examples:
$ cat x.pl #!/usr/bin/env perl use strict; use warnings; my @stuff = (49, (49), "49", "(49)", "123", "76 trombones", "123 E 31st", "123E31st street"); for my $t (@stuff) { print "t=<$t>, t+0=", $t+0, "\n\n"; } Roboticus@Waubli ~ $ perl x.pl t=<49>, t+0=49 t=<49>, t+0=49 t=<49>, t+0=49 Argument "(49)" isn't numeric in addition (+) at x.pl line 8. t=<(49)>, t+0=0 t=<123>, t+0=123 Argument "76 trombones" isn't numeric in addition (+) at x.pl line 8. t=<76 trombones>, t+0=76 Argument "123 E 31st" isn't numeric in addition (+) at x.pl line 8. t=<123 E 31st>, t+0=123 Argument "123E31st street" isn't numeric in addition (+) at x.pl line +8. t=<123E31st street>, t+0=1.23e+33
So if you really want to treat them as numbers, you'll need to come up with the appropriate rules (and code) to determine what number to convert them into. If it's as simple as stripping off parenthesis, you could do it with s/[()]//g, but be sure to think about all the special cases you may run into...
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: numbers in parentheses not considered numeric values??
by gghelpneeded (Novice) on Aug 07, 2015 at 22:37 UTC | |
by roboticus (Chancellor) on Aug 08, 2015 at 03:21 UTC | |
by Anonymous Monk on Aug 07, 2015 at 23:10 UTC |