+ -
当前位置:首页 → 问答吧 → 问个关于匿名数组的问题

问个关于匿名数组的问题

时间:2011-06-30

来源:互联网

@array=( [1,2,3],[4,5,6],[7,8,9]); 其每个元素为一个匿名数组的引用,这个没错,但是我想问问,如果使用@arry=qw( [1,2,3] [4,5,6] [7,8,9] );这样的话为什么会在遍历的时候提示说有存在软引用?

作者: lynncate   发布时间: 2011-06-30

本帖最后由 climby 于 2011-06-30 11:18 编辑

qw 的操作是将每个单词作为一个数组元素,在
  1. @array=qw([1,2,3] [4,5,6] [7,8,9])
复制代码
中, [1,2,3] 是按一个类似字面的字符串, 还是按一个匿名的数组引用呢? 有歧义。
我想这就是提示你有软引用的原因吧。
写代码的时候,尽量摒弃这种歧义,理解起来费劲,不如直接
  1. @array= ([1,2,3], [4,5,6],[7,8,9]);
复制代码
简洁明了。

作者: climby   发布时间: 2011-06-30



QUOTE:
qw/STRING/
Evaluates to a list of the words extracted out of STRING, using embedded whitespace as the word delimiters. It can be understood as being roughly equivalent to:
    split(' ', q/STRING/);
the differences being that it generates a real list at compile time, and in scalar context it returns the last element in the list.

作者: zhlong8   发布时间: 2011-06-30

谢谢,已经明白了

作者: lynncate   发布时间: 2011-06-30