Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Remove letters from variables used in math operation?

by tobyink (Abbot)
on Dec 08, 2012 at 21:17 UTC ( #1007929=note: print w/replies, xml ) Need Help??


in reply to Remove letters from variables used in math operation?

Easy peasy!

use warnings; while ($line = <DATA>){ chop($line); ($a,$b,$c,$d,$e,$f,$g)=split(",",$line); no warnings qw(numeric); $sum = ($a+$b+$c+$d+$e+$f+$g); print $sum; } __END__ 86f,934e,92,102i,14,19,222,

The numeric warning is not compulsory; it's not even enabled by default (hence you needing to explicitly type use warnings). If it's not helping you, then turn it off.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Remove letters from variables used in math operation?
by eyepopslikeamosquito (Chancellor) on Dec 08, 2012 at 22:08 UTC

    While switching off warnings is OK when you are sure of the format of your data, be aware of subtle pitfalls. In particular, scientific notation. For example:

    '934e' + 1; # value is 935 '934e0' + 1; # ok, value is still 935 '934e3' + 1; # oops, value is 934001 (scientific notation)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007929]
help
Chatterbox?
[thao4]: thao4
[hippo]: Indeed you are.
[thao4]: Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the patern "Model Regle" by "Heath Rule A" in this new line (30 line
[marto]: good morning all
[hippo]: Welcome. Tell me, have you read perlintro? That's a great place to start.
[thao4]: I seach to do that since a week but I can't found the answer in google. Thank for your help
[Eily]: hello thao4 (and hello all :D), you should [id://http:// perlmonks.org/ index.pl?node_id= 479#post|open a question on Seekers of Perl Wisdom], be sure to include whatever you have tried that didn't work, or only does the job partially
[thao4]: yes, I do a little perl since some years but not fréquently, I can correct the triggers in Clearcase of IBM, but write the code : no
[Eily]: meh, such good link ...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2018-02-21 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (276 votes). Check out past polls.

    Notices?