“如果这里被初始化成一个字符串”不知道你说的是什么?
字符串不是列表,所以不能代替 $rlEntry 被 push 到 %year_index or %
category_index 中去。
建议看看 perlreftut 手册,你的问题应该能解决。不行再看看 perldata。

On 三, 2009-01-07 at 03:06 -0800, [email protected] wrote:
> 谢谢,但是这个引用并没有任何值对吧?如果这里被初始化成一个字符串,它能实现的效果因该也是相同的对吗?
> 
> On 1月7日, 下午6时20分, Changying Li <[email protected]> wrote:
> > "[email protected]" <[email protected]> writes:
> > > open (F, "oscar.txt") || die "Could not open database: $:";
> > > %category_index = (); %year_index = ();
> > > while ($line = <F>) {
> > >     chomp $line;
> > >     ($year, $category, $name) = split (/:/, $line);
> > >     create_entry($year, $category, $name) if $name;
> > > }
> > > sub create_entry {             # create_entry (year, category, name)
> > >     my($year, $category, $name) = @_;
> > >     # Create an anonymous array for each entry
> > >     $rlEntry = [$year, $category, $name];
> > >     # Add this to the two indices
> > >     push (@{$year_index {$year}}, $rlEntry);         # By Year
> > >     push (@{$category_index{$category}}, $rlEntry); # By Category
> > > }
> > > -----------------------------
> > > 这里push (@{$year_index {$year}}, $rlEntry);
> > > 我的理解是:
> > > $year_index{$year}应该是%year_index的一个元素,但是没有被赋予任何值,那么在之前加...@是什么意思呢?没有变量名的数
> > > 组?但是打印出来的话又看到$year_index{$year}是一个数组的引用,是在无法理解。
> >
> > 它被初使化为一个数组引用,比如:
> > [chy...@arch yi] perl -e 'push @$a,"hello"; print @$a;'
> > hello%    
> >
> >
> >
> > --
> >
> > Thanks & Regards
> >
> > Changying Li
> > 


--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina 论坛”论坛。
 要在此论坛发帖,请发电子邮件到 [email protected]
 要退订此论坛,请发邮件至 [email protected]
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

回复