That's slick. I like it. I feel getting better at climbing down hash trees.
One thing hangs me up. What's "{$s}++" doing at the end of:
$h{${$lis{$i}{$j}}[1]}{${$lis{$i}{$j}}[0]}{$s}++;
{$s} looks like one hash deeper with key $s, sorted at the end of your script.
But then ++. Watsit ?
Another Perl trick I've got to learn ?
Thanks a lot.
- -
On Tue, 21 Jan 2003 16:39:39 -0800, Richard Cook wrote:
>#!/usr/bin/perl -w
>BEGIN { $^W = 1 }
>use strict;
>my %lis; #age sex
>$lis{cat}{Zoe}=["9","female"];
>$lis{dog}{Max}=["8","male"];
>$lis{pig}{Joe}=["6","barrow"];
>$lis{cat}{Sam}=["1","female"];
>$lis{dog}{Bob}=["2","male"];
>$lis{cat}{Kat}=["5","female"];
>$lis{pig}{Sly}=["7","barrow"];
>$lis{cat}{Tom}=["1","male"];
>$lis{pig}{Zig}=["3","barrow"];
>print "-"x32,"\n";
>my %h;
>for my $i (keys %lis){
> for my $j (keys %{$lis{$i}}){
> my $s = ", a pet $i named $j; ";
> $h{${$lis{$i}{$j}}[1]}{${$lis{$i}{$j}}[0]}{$s}++;
> } #sex age
>}
>for my $h (sort { $a cmp $b } keys %h){
> print "sex $h: ";
> for my $i (sort {$a <=> $b} keys %{$h{$h}}){
> print "age $i";
> for my $s (sort keys %{$h{$h}{$i}}){
> print "$s";
> }
> }
> print "\n";
>}
>#END