"[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 访问该论坛
-~----------~----~----~----~------~----~------~--~---

回复