Re: perl - data structure build to transpose data
From: Anno Siegel (anno4000_at_lublin.zrz.tu-berlin.de)
Date: 08/30/04
- Next message: Martien Verbruggen: "Re: Resizing JPG images with Perl?"
- Previous message: Mac: "Re: Larry Wall & Cults"
- In reply to: David K. Wall: "Re: perl - data structure build to transpose data"
- Next in thread: David K. Wall: "Re: perl - data structure build to transpose data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Aug 2004 00:05:00 GMT
David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> > David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> >> srigowrisn@hotmail.com (shree) wrote:
> >
> > [specifications]
> >
> >> Yet another way:
> >
> > Shree got lucky, undeservedly.
>
> I'm bored.
To summarize (time for bed here, so I'm in a summarizing mood) and
to take the chance to plug Text::Table for real, I've put the parts
together. It's still far from a one-liner, but it's about as compact
as it gets while trying to keep it readable.
Anno
use Text::Table;
my $tb = Text::Table->new( ( '&left') x 5);
my ( @months, %month_id);
@months = split for ( scalar <DATA> );
@month_id{ @months} = 1 .. @months;
while ( ! eof DATA ) {
my ( $supp_name, %supp_data);
for ( 1 .. 3 ) {
die "bad data $_" if eof;
my ( $name, $type, @data) = split /\s+/, <DATA>;
$supp_name = $name if $name;
@{$supp_data{$type}}{@months} = @data;
}
for my $month ( @months) {
for ( sort keys %supp_data ) {
$tb->add( $supp_name, $_, $supp_data{ $_}->{ $month},
$month, $month_id{ $month});
}
}
}
print $tb;
__DATA__
Jan-04 Feb-04 Mar-04
Supp1 % 20.00% 10.17% 7.14%
Defects 200 122 100
Total 1000 1200 1400
Supp2 % 3.00% 1.82% 1.90%
Defects 60 40 40
Total 2000 2200 2100
- Next message: Martien Verbruggen: "Re: Resizing JPG images with Perl?"
- Previous message: Mac: "Re: Larry Wall & Cults"
- In reply to: David K. Wall: "Re: perl - data structure build to transpose data"
- Next in thread: David K. Wall: "Re: perl - data structure build to transpose data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|