我在Perl中遇到了一些内存问题.当我填满一个大哈希时,我无法将内存释放回操作系统.当我使用标量和使用时undef,它会将内存返回给操作系统.
这是我写的测试程序.
#!/usr/bin/perl
###### Memory test
######
## Use Commands
use Number::Bytes::Human qw(format_bytes);
use Data::Dumper;
use Devel::Size qw(size total_size);
## Create Varable
my $share_var;
my %share_hash;
my $type_hash = 1;
my $type_scalar = 1;
## Start Main Loop
while (true) {
&Memory_Check();
print "Hit Enter (add to memory): "; <>;
&Up_Mem(100_000);
&Memory_Check();
print "Hit Enter (Set Varable to nothing): "; <>;
$share_var = "";
$share_hash = ();
&Memory_Check();
print "Hit Enter (clean data): "; <>;
&Clean_Data();
&Memory_Check();
print …Run Code Online (Sandbox Code Playgroud) perl version 5.18
我遇到了perl JSON编码器的问题,并在浮点数周围加上引号.
看示例代码:
use JSON;
use Data::Dumper;
my $float = 1.2;
my $t = {
float => $float
};
my $json1 = encode_json($t);
print Dumper $t;
my $json2 = encode_json($t);
print $json1 . "\n";
print $json2 . "\n";
Run Code Online (Sandbox Code Playgroud)
输出:
$VAR1 = {
'float' => '1.2',
'integer' => 1
};
{"float":1.2,"integer":1}
{"float":"1.2","integer":1}
Run Code Online (Sandbox Code Playgroud)
正如您在使用Dumper后看到的那样,JSON编码器会添加引号.有什么想法会发生这种情况吗?
不在上面的示例代码中,但在生产中,除非我添加.01,否则我无法删除引号.即使*=*1也不起作用.