IsabelleFr
Novice
Feb 16, 2013, 8:56 AM
Post #1 of 6
(1010 views)

Multiples of 10

Can't Post


Hi :) I'm trying to make a script that allows me to 'join' complex numbers like 'one hundred thousand two hundred fifty dogs' to 100250. I have a script that allows me to transform letters to numbers, but the problem is that it takes a number like 'two hundred' and makes it '2 100'. You see the problem... I would like, after making it from letters to numbers, to be able to join it... i'll post what i tried:
use strict; use warnings; my %norm = ( 'un' => 1, 'une' => 1, 'deux' => 2, 'trois' => 3, 'quatre' => 4, 'cinq' => 5, 'six' => 6, 'sept' => 7, 'huit' => 8, 'neuf' => 9, 'dix' => 10, 'onze' => 11, 'douze' => 12, 'treize' => 13, 'quatorze' => 14, 'quinze' => 15, 'seize' => 16, 'dixsept' => 17, 'dixhuit' => 18, 'dixneuf' => 19, 'vingt' => 20, 'trente' => 30, 'quarante' => 40, 'cinquante' => 50, 'soixante' => 60, 'soixantedix' => 70, 'quatrevingt' => 80, 'quatrevingtdix' => 90, 'cent' => 100, 'cents' => 100, 'mille' => 1000, 'million' => 1000000, 'millions' => 1000000, 'milliards' => 1000000000, ); while (my $ligne = <STDIN>) { chomp $ligne; if ($ligne =~ /^(\d+?)\s*%.*/ig){ my $multi = $1 / 100; print $multi. "\n"; } if ($ligne =~ s/(:?une?deuxtroisquatrecinqsixsepthuitneufdixonzedouzetreizequatorzequinzeseizedixseptdixhuitdixneufvingttrentequarantecinquantesoixantesoixantedixquatrevingtquatrevingtdixcents?millemillions?milliards?)/$norm{lc $1}/egi){ print $ligne, "\n"; } else { print $ligne."\n"; } } (u will notice its in french because i'm french lol ;P) It is not perfect because to not skip lines where i already have numbers, i put a print $ligne, but ofc it prints twice a line when it's a X%. I need help =/
