Subject: | Overriding variables in non-OO approach |
Date: | Tue, 3 Jan 2012 17:43:19 -0500 |
To: | <bug-Number-Format [...] rt.cpan.org> |
From: | "Milan Milicic" <milanm [...] portfolioaid.com> |
Hello,
I want to use Number::Format in non-OO manner (legacy code). I export :vars, override $NEG_FORMAT and a few other variables and then call "format_number" method. It disregards any of my variable overrides and goes on with default values instead.
Here is the script:
Show quoted text
--- START ---
#!/usr/bin/perl
use Number::Format qw(:vars :subs);
# print out defaults
print "\n------------------------------------\n";
print " THOUSANDS_SEP = $THOUSANDS_SEP \n";
print " DECIMAL_POINT = $DECIMAL_POINT \n";
print " MON_THOUSANDS_SEP = $MON_THOUSANDS_SEP \n";
print " MON_DECIMAL_POINT = $MON_DECIMAL_POINT \n";
print " INT_CURR_SYMBOL = $INT_CURR_SYMBOL \n";
print " DECIMAL_DIGITS = $DECIMAL_DIGITS \n";
print " DECIMAL_FILL = $DECIMAL_FILL \n";
print " NEG_FORMAT = $NEG_FORMAT \n";
print " KILO_SUFFIX = $KILO_SUFFIX \n";
print " MEGA_SUFFIX = $MEGA_SUFFIX \n";
print " GIGA_SUFFIX = $GIGA_SUFFIX \n";
print " KIBI_SUFFIX = $KIBI_SUFFIX \n";
print " MEBI_SUFFIX = $MEBI_SUFFIX \n";
print " GIBI_SUFFIX = $GIBI_SUFFIX \n";
print "------------------------------------\n\n";
# override a few variables
$THOUSANDS_SEP = '.';
$NEG_FORMAT = '<<x>>';
$DECIMAL_DIGITS = 1;
my $number = -2000.00;
# Expected: <<2000.0>>
# Received: -2,000.00
print "number displays as: " . format_number($number, 2, 1) . "\n\n";
--- END ---
And here is the output on my system:
------------------------------------
THOUSANDS_SEP = ,
DECIMAL_POINT = .
MON_THOUSANDS_SEP = ,
MON_DECIMAL_POINT = .
INT_CURR_SYMBOL = USD
DECIMAL_DIGITS = 2
DECIMAL_FILL = 0
NEG_FORMAT = -x
KILO_SUFFIX = K
MEGA_SUFFIX = M
GIGA_SUFFIX = G
KIBI_SUFFIX = KiB
MEBI_SUFFIX = MiB
GIBI_SUFFIX = GiB
------------------------------------
number displays as: -2,000.00
Any help appreciated.
Cheers,
- M
CONFIDENTIALITY WARNING:
This message is intended only for the use of the individual or entity to which it is addressed, and may contain information which is privileged, confidential, proprietary or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying or in any way using this message or its attachments. If you have received this communication in error, please notify the sender, and destroy and delete any copies you may have received.