perl改变hash的引用 [英] perl change ref of hash

查看:105
本文介绍了perl改变hash的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到了这个,找不到答案。我试图看看是否有可能改变散列的引用。换句话说,我有一个散列函数和一个返回hashref的函数,并且我想让我的散列点指向由此ref指定的内存中的位置,而不是复制它指向的散列的内容。代码看起来像这样:

 %hash = $ h-> hashref; 

我明显的猜测是它应该是这样的:

  \%hash = $ h-> hashref; 

但是会给出错误:


无法修改标量赋值中的引用构造函数

我尝试了其他一些方法,但没有任何成效。是我尝试实际上可能吗?

解决方案

一个实验性的功能,看起来可以让你做你正在描述的内容< Perl 5.21.5添加了一个href =https://metacpan.org/pod/release/ABIGAIL/perl-5.21.5/pod/perldelta.pod =nofollow> ,它是一个开发版本(请参阅通过引用进行别名)。

I ran into this and couldn't find the answer. I am trying to see if it is possible to "change" the reference of a hash. In other words, I have a hash, and a function that returns a hashref, and I want to make my hash point to the location in memory specified by this ref, instead of copying the contents of the hash it points to. The code looks something like this:

%hash = $h->hashref;

My obvious guess was that it should look like this:

\%hash = $h->hashref;

but that gives the error:

Can't modify reference constructor in scalar assignment

I tried a few other things, but nothing worked. Is what I am attempting actually possible?

解决方案

An experimental feature which would seemingly allow you to do exactly what you're describing has been added to Perl 5.21.5, which is a development release (see "Aliasing via reference").

这篇关于perl改变hash的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆