简体   繁体   English

Perl错误:不是参考

[英]Perl error: not a reference

I recently migrated some Perl code from SunSolaris to a Linux(Ubuntu) box of 64 bit. 我最近将一些Perl代码从SunSolaris迁移到64位的Linux(Ubuntu)盒子。 After the migration Storable.pm is breaking with the following error: 迁移后Storable.pm出现以下错误:

Byte order is not compatible at /usr/lib/perl/5.18/Storable.pm, at /home/VD/Cache.pm line 347.

After some research on the internet I found that I need to use nfreeze instead of thaw , but now I receive the following error: 在互联网上进行一些研究后,我发现我需要使用nfreeze而不是thaw ,但现在我收到以下错误:

not a reference at /home/VD/Cache.pm line 347.

Any suggestions how to fix this? 有任何建议如何解决这个问题?

    sub get
    {
      my($self, $type, $param_ref) = @_;
       #return 1 if(!$self->{'INI'}{'sf.system.cache.enabled'});

if($self->{'INI'}{'sf.system.cache.database.enabled'})
{
    ### DATABASE
    my $param = $self->SF::Cache::convert_parameter($type, $param_ref);

    if($self->SF::Cache::CACHE_TABLE_USERCONTENT && $$param{'type'} == 2)
    {
        ### user-content
        my $query = 'SELECT PARAM_CONTENT AS C, DATA AS D FROM    sf_cache_usercontent WHERE SITE=? AND PARAM_USER=?';
        my $bindvar = { 1=>$self->{'site'}, 2=>$$param{'user'} };
        my $sth = $self->db_select($query, $bindvar);
        #print SF::Util::debug_dumpquery($query, $bindvar);
        return undef if($self->{'Error'});

        my %usercontent;
        undef(%usercontent);
        while(my $hashref = $self->db_fetch($sth))
        {
            $usercontent{$$hashref{'C'}} = $$hashref{'D'};# ? 1 : 0;
        }

        return \%usercontent;
    }
    else
    ### ******************************************************************************************************
    {
        my $ret = $self->SF::Cache::get_database('DATA', $param);

        return Storable::nfreeze($ret) if(defined $ret);
    }
}
else
{
    ### FILESYSTEM
    my $filename = $self->SF::Cache::filename($type, $param_ref);
    if($filename && -e $filename)
    {
        if($self->{'INI'}{'sf.system.cache.lock.enabled'} && defined  &lock_retrieve)
        {
            return lock_retrieve $filename;
        }
        else
        {
            return retrieve $filename;
        }
    }
    else
    {
        $! = 0;
    }
}
return undef;
}

回到你的原始系统, thaw然后nfreeze的文件来修复它。

perl -MStorable=nstore,retrieve -e'nstore(retrieve($ARGV[0]), $ARGV[1])' file fixed

So, "not a reference" means ... exactly what it says on the tin. 因此,“不是参考”意味着......正是它在锡上所说的。 Can you try printing the thingy with Data::Dumper from comments it's this line: 你可以尝试使用Data::Dumper从评论中打印出这个东西:

return Storable::nfreeze($ret) if(defined $ret)

So - what does: 那么 - 做什么:

print Dumper $ret; 

produce? 生产? Is it a reference? 它是一个参考?

I'm not so sure though that you're right about needing nfreeze instead of thaw , because they both do different things. 我不太确定你是否正确需要nfreeze而不是thaw ,因为他们都做不同的事情。 freeze packs a variable; freeze变量; thaw unpacks it. thawthaw So nfreeze can replace freeze . 所以nfreeze可以取代freeze

But the core purpose of doing this is to transfer your packed up scalar to another program on another architecture. 但这样做的核心目的是将打包的标量转移到另一个体系结构上的另一个程序。 Is this what you're doing? 这是你在做什么的?

If so, can I suggest instead considering transferring it as JSON or XML instead? 如果是这样,我可以建议改为将其转换为JSONXML吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM