Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse scientific integer representation in perl

Tags:

parsing

perl

What is the most elegant way to parse an integer given in scientific representation, i.e. I have an input file with lines like

value=1.04738e+06

Sure I can match the all the components (leading digit, decimal positions, exponent) and calculate the result, but it seems to me there is a more straight-forward way.

like image 550
dcn Avatar asked Dec 21 '22 09:12

dcn


1 Answers

% perl -e 'print "1.04738e+06" + 0'
1047380

You just need to coerce it to a number and Perl will DWIM.

like image 104
Wooble Avatar answered Dec 30 '22 23:12

Wooble