shadowfox has asked for the wisdom of the Perl Monks concerning the following question:
The value at the end, 1469 is accurate but I'd like to take out the letters and avoid the warnings as they are not needed in my data context.use warnings; while ($line = <DATA>){ chop($line); ($a,$b,$c,$d,$e,$f,$g)=split(",",$line); $sum = ($a+$b+$c+$d+$e+$f+$g); print $sum; } __END__ 86f,934e,92,102i,14,19,222,
I tried using (s/\D//g) in various ways but I'm just getting it wrong, can this be easily done without altering each variable before the math operation individually? Please don't lecture me on strictures, this is a small example of my problem, not polished code.Argument "934e" isn't numeric in addition (+) at test.pl line 7, <DATA +> line 1. Argument "86f" isn't numeric in addition (+) at test.pl line 7, <DATA> + line 1. Argument "102i" isn't numeric in addition (+) at test.pl line 7, <DATA +> line 1. 1469
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remove letters from variables used in math operation?
by AnomalousMonk (Archbishop) on Dec 08, 2012 at 21:22 UTC | |
|
Re: Remove letters from variables used in math operation?
by tobyink (Canon) on Dec 08, 2012 at 21:17 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 08, 2012 at 22:08 UTC | |
|
Re: Remove letters from variables used in math operation?
by graff (Chancellor) on Dec 09, 2012 at 03:31 UTC | |
|
Re: Remove letters from variables used in math operation?
by BillKSmith (Monsignor) on Dec 09, 2012 at 03:22 UTC | |
|
Re: Remove letters from variables used in math operation?
by shadowfox (Beadle) on Dec 08, 2012 at 21:32 UTC |