- 论坛徽章:
- 0
|
本帖最后由 ulmer 于 2013-10-01 00:26 编辑
回复 1# kernel69
Simply using reference array/hash => Hash of Array for example:
- use strict;
- # Load data
- my @data =<DATA>;
- # Create data structure Hash of Array
- my %HoA = ();
- foreach my $line (@data) {
- chomp $line;
- # Split columns
- my ($c1, $c2, $c3) = split /\s+/, $line, 3;
- # Column2 as key and column3 as array items to append
- push @{$HoA{$c2}}, $c3;
- }
- # Access the data structure
- foreach my $key (sort keys %HoA) {
- # derefernce Array in Hash and sort it to get max and min.
- my @ary = sort @{$HoA{$key}};
- # show
- printf ("%s counted %s times, max=%s, min=%s\n",
- $key, scalar(@ary), $ary[-1], $ary[0]);
- }
- __DATA__
- 111 16644211 348795021
- 111 16644211 348795368
- 111 16644211 348797001
- 111 16644211 348797826
- 111 22443489 348795333
- 111 67384560 348795445
- 111 67384560 348795879
复制代码 Happy National holiday |
|