in reply to New to Perl
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @data = <DATA>; my $struct; my ($case, $table, $man, $seat, $round, $who, $what); for (@data){ /^\s*$/ and next; /^\s*#case\s+\w+:\s+(\d+)/i and $case = $1 and next; /^\s*people\s.+=\s*(\d+)/i and $table = $1 and next; /^\s*round\s+(\d+)/i and $round = $1 and next; /^\s*seat\s+(\d+):\s+(\w+)/i and ($seat, $man) = ($1, $2); /^(\w+)\s+(.+)?\s*$/ and ($who, $what) = ($1, $2); $struct->{$case}{$table}{'seat'}{$man} = $seat if $seat; push @{$struct->{$case}{$table}{'round'}{$round}{$who}}, $what if $ +round; } for my $case (keys %$struct){ for my $table (keys %{$struct->{$case}}){ for my $round (keys %{$struct->{$case}{$table}{'round'}}){ for my $man (sort keys %{$struct->{$case}{$table}{'round'}{$round}} +){ print "player: $man "; print "case: $case "; print "seat: $struct->{$case}{$table}{'seat'}{$man} "; print "round: $round "; print "QA: ", join '. ', @{$struct->{$case}{$table}{'round'}{$ro +und}{$man}}, "\n"; } } } } #print Dumper($struct); __DATA__ #Case Number: 12345 People at table = 5 Seat 1: Joe Seat 2: Steve Seat 3: Mary Seat 4: Jill Seat 5: Bob Jill speaks first Round 1: Jill says good Bob doesn't talk Joe says bad Steve says good Mary doesn't talk Jill says that's enough Mary talks for years Steve says that's not enough Round 2: Next question Jill says bad Bob doesn't talk Joe says bad Steve says bad Mary doesn't talk Bob says that's enough
Which has the following output:
player: Bob case: 12345 seat: 5 round: 1 QA: doesn't talk.
player: Jill case: 12345 seat: 4 round: 1 QA: says good. says that's enough.
player: Joe case: 12345 seat: 1 round: 1 QA: says bad.
player: Mary case: 12345 seat: 3 round: 1 QA: doesn't talk. talks for years.
player: Steve case: 12345 seat: 2 round: 1 QA: says good. says that's not enough.
player: Bob case: 12345 seat: 5 round: 2 QA: doesn't talk. says that's enough.
player: Jill case: 12345 seat: 4 round: 2 QA: says bad.
player: Joe case: 12345 seat: 1 round: 2 QA: says bad.
player: Mary case: 12345 seat: 3 round: 2 QA: doesn't talk.
player: Steve case: 12345 seat: 2 round: 2 QA: says bad.
|
|---|