我不知道,如果「擴展」是正確的字,但這裏是我想怎樣做=)如何擴大數組哈希?
這個腳本
#!/usr/bin/perl
use warnings;
use strict;
my %HoA = (
group1 => [ "user1", "user2" ],
group2 => [ "group1", "user3" ],
group3 => [ "group1", "group2" ],
group4 => [ "group3", "user2" ],
);
foreach my $group (keys %HoA) {
print "$group: @{ $HoA{$group} }\n"
}
輸出
group1: user1 user2
group2: group1 user3
group3: group1 group2
group4: group3 user4
我希望是用成員替換數組中的組。即所以輸出和$HoA
成爲
group1: user1 user2
group2: user1 user2 user3
group3: user1 user2 user3
group4: user1 user2 user3 user4
也許「查找和替換」並刪除重複將是我想做些什麼更好的解釋?
如果你有循環引用?即如果group1有group2,group2有group1呢? – CanSpice 2011-01-24 21:52:33
然後我想運送該組,並打印一個錯誤。 – 2011-01-24 21:53:52