http://qs321.pair.com?node_id=852569


in reply to Re^4: Change decimal point temporarily
in thread Change decimal point temporarily

I don't think so. That's the opposite of what he said (changing the decimal point from "." to ","), and it's the opposite of what his code does.

I see what you mean, but it still make no sense since he says setlocale works.

$ perl -we'use POSIX; setlocale LC_NUMERIC, "fr_FR"; print 0+"123,45"' Argument "123,45" isn't numeric in addition (+) at -e line 1. 123

Replies are listed 'Best First'.
Re^6: Change decimal point temporarily
by lima1 (Curate) on Aug 03, 2010 at 00:32 UTC
    Hm, It seems to work if you use locale:
    perl -we 'use POSIX; use locale; setlocale LC_NUMERIC, "fr_FR"; $x = " +123,45"; $x+=0.1; print $x; setlocale LC_NUMERIC, ""; $x += 0.1; prin +t $x;'
    Update: this does not work:
    perl -we 'use POSIX; use locale; setlocale LC_NUMERIC, "fr_FR"; $x = " +123,45"; print $x; setlocale LC_NUMERIC, ""; $x += 0.1; print $x;'
    So what I do now is to add 0 if it looks_like_number() and everything works fine. At least what I've tested until now...

      ah! In that case,

      (my $tmp = $s) =~ s/,/./; $s = $tmp if looks_like_numbers($tmp);

      You'd be better of specifying which columns are numeric, though. Text::CSV_XS can even take advantage of that information if you tell it (via types).