in reply to why use a hash instead of an array
Hi DarrenSol
Wonderful answers has been given, but maybe this little example / question could also "say" something.
If I give the following:
And I ask that for these:teacher students professor students school class teacher desk table chalk borad class school teacher
Solution:use strict; use warnings; my %hash; while(<DATA>){ chomp; $hash{$_}++ for split; } print join $/ => sort keys %hash; print $/,$/, join $/ => grep {$_ if $hash{$_} > 1} sort keys %hash; __DATA__ teacher students professor students school class teacher desk table chalk borad class school teacher
borad chalk class desk professor school students table teacher
class school students teacher
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: why use a hash instead of an array
by 5mi11er (Deacon) on Jun 11, 2013 at 21:18 UTC | |
Re^2: why use a hash instead of an array
by Lotus1 (Vicar) on Jun 12, 2013 at 19:04 UTC | |
by LanX (Saint) on Jun 12, 2013 at 21:53 UTC | |
by Lotus1 (Vicar) on Jun 12, 2013 at 22:54 UTC | |
by LanX (Saint) on Jun 12, 2013 at 23:09 UTC |