perl改变hash的引用 [英] perl change ref of hash
问题描述
%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屋!