Chinaunix首页 | 论坛 | 博客
  • 博客访问: 855759
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-20 22:02:41

@array = qw /test this that a/;
$a = \@array;
$b = $a;
$c = \@array;
there are three times reference to @array.

Perl recycles the memory for the array only when all references (including the name of the array) go away. In this case, Perl only reclaims memory when @array and all the references we created to it disappear.

  1. my $ref;

  2. {
  3.   my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
  4.   $ref = \@skipper;

  5.   print "$ref->[2]\n"; # prints jacket\n
  6. }

  7. print "$ref->[2]\n"; # still prints jacket\n
after the block, the reference to the array still exists,

At this point, the five-element list is in an anonymous array, which is a fancy term for an array without a name.

The data stays alive until we destroy the last reference:

$ref = undef; #

阅读(742) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~