mouse.rice
《Intermediate Perl》中一段CODE如何理解?
[quote]Imagine for a moment that the intermediate variables are all part of a subroutine:
my @all_with_names;
sub initialize_provisions_list {
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
my @skipper_with_name = ('The Skipper', /@skipper);
my @professor = qw(sunscreen water_bottle slide_rule batteries radio);
my @professor_with_name = ('The Professor', /@professor);
my @gilligan = qw(red_shirt hat lucky_socks water_bottle);
my @gilligan_with_name = ('Gilligan', /@gilligan);
@all_with_names = ( # set global
/@skipper_with_name,
/@professor_with_name,
/@gilligan_with_name,
);
}
initialize_provisions_list( );
We set the value of @all_with_names to contain three references. Inside the subroutine we have named arrays with references to arrays first placed into other named arrays. [color=Red]Eventually, the values end up in the global @all_with_names. However, as the subroutine returns, the names for the six arrays disappear. Each array has had one other reference taken to it, making the reference count temporarily two, and then back to one as the name disappears.[/color] Because the reference count is not yet zero, the data continues to live on, although it is now referenced only by elements of @all_with_names.
[/quote]
[color=SeaGreen][b]----------------单词没有问题,但是翻译器来总怪怪的,尤其红色部分,以致无法整体把握文章在讲些什么。请大家用程序语言帮解释解释,谢谢![/b][/color]
[[i] 本帖最后由 mouse.rice 于 2008-7-2 11:48 编辑 [/i]]