在Perl中更改哈希的引用 [英] Change ref of hash in Perl

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

问题描述

我遇到了这个,找不到答案.我正在尝试查看是否有可能更改"目录.哈希的引用.换句话说,我有一个哈希和一个返回哈希引用的函数,我想使哈希指向此引用所指定的内存中的位置,而不是复制哈希所指向的内容.代码看起来像这样:

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;

但是会出现错误:

无法在标量分配中修改引用构造函数

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中更改哈希的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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