2016-09-18 29 views
0

我有一个散列,其中包含一个大于128个字符的值,现在我通过nstore函数将该散列存储在文件中。当散列值大于128个字符时,文件损坏perl

use strict ; 
use warnings ; 
use Storable qw(store nstore retrieve); 

my $hash = { 

###value more than 128 char 
'a.key.value.in.a.hash.that.will.be.sored.in.a.file' => 'some.value.that.is.not.getting.stored.on.the.remote.server.strange.enough.if.length.is.greate.than.128.char.may.some.perl.issueee' 
}; 

my $temp_dir = 'C:\TEMP\log'; 

nstore($hash, "$temp_dir/temp_file"); 

现在我试图通过cgi上传功能从本地上传文件到远程服务器。

通过nstore产生的本地机器上http://localhost/some/api?file=file

sub post { 


    my $q = new CGI; 
    my $filename = $q-param('file'); 
    my $upload_filehandle = $q->upload("file"); 

    open (UPLOADFILE, ">$upload_dir/$filename") or die "$!"; 
    binmode UPLOADFILE; 

    while (<$upload_filehandle>) { 
     print UPLOADFILE; 
    } 

    close UPLOADFILE; 

} 

的问题是,如果哈希值长度大于128比remte计算机上的文件是越来越损坏,我无法以检索回来witrh可存储的检索功能

+0

我需要升级cgi吗?我能够直接scp文件没有问题,但当我使用上传功能,看到这个问题。 –

+0

您可以尝试使用'read()'而不是'readline()'(又名'''''';另外,'$ q-param('file')'是一个错字。 – oals

+0

此外,你可以给它的文件的十六进制转储,因为它存储在服务器上? * nix上的'hexdump -C yourfilehere'。 – oals

回答

-2

您的示例没有显示nstore()被赋予散列引用作为其第一个参数。

nstore(\$hash, "$temp_dir/temp_file"); 
+0

我只通过散列引用 –

+1

'my $ hash = {...};'*是*散列引用,因此不需要在'nstore()'调用中引用它。 – stevieb