in reply to Re^3: Tricky Problem
in thread Tricky Problem

This part
push @{$H{$1}{$3}{head}}, $2; push @{$H{$1}{$3}{tail}}, grep{$_} split ':', $4;

and this part too
foreach my $k1 (sort {$a <=> $b} keys %H) { print "$k1\n"; foreach my $k2 (sort {$a <=> $b} keys %{$H{$k1}}) { print "$k2\n"; my $tail = join ':', sort {$a <=> $b} @{$H{$k1}{$k2}{tail}}; foreach my $head (sort {$a <=> $b} @{$H{$k1}{$k2}{head}}) { print "$head|$tail\n"; } } }
Thanks :) Krish

Replies are listed 'Best First'.
Re^5: Tricky Problem
by ysth (Canon) on Aug 19, 2004 at 16:16 UTC
    push @ARRAY, LIST adds the elements in LIST to the end of an array. @{ EXPR } uses the array that EXPR is a reference to. $H{$1}{$3}{head} looks up the array reference in a hash of hashes of hashes of arrays. $1, $2, $3, and $4 are parts captured from within the first, second, third, and fourth set of (parens) in the regex match. split ":", $4 breaks up $4 into a list of pieces wherever there's a ":" (where the results do not include the ":"). grep{$_} filters the list produced by split and removes any false values. (In your example, you show a "350:" that split would break into ("350",""); the grep removes the "".)

    Update: is that the kind of help you want? A higher level description of the code is that it reads through all the data, storing it under two levels of keys so it can be easily dumped out in order by the 100-/200- field and the ER/MA field within that.

      hey thanks..this is the best way to learn perl i guess
      Krish