Re: perl - data structure build to transpose data

From: Anno Siegel (anno4000_at_lublin.zrz.tu-berlin.de)
Date: 08/30/04


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



Relevant Pages

  • Service Competence
    ... and you're a) lucky if he shows up to do an estimate, ... install crown molding in our master bathroom. ... twenty six compound mitre cuts, only a handful of which were ninety ... And because none of the wall to wall, ...
    (rec.sport.football.college)
  • Re: Stolen Les Pauls, Etc.
    ... Margaret>>> ... I just got lucky. ... I found it on the wall for sale at Guitars`R`Us in ...
    (rec.music.makers.guitar.jazz)
  • Re: More Ebay Madness
    ... Yep, we were lucky here in the east Keith, no major flooding problems. ... Think I'm going to end up building a dwarf wall to keep the water all ... incredibly lucky that it just stayed below the floorboard level by an ...
    (uk.rec.models.engineering)
  • Re: GOD=G_uv INVISIBLE WORLD
    ... If you're not lucky, or that ruthless, ... Think of spending a lifetime torn between those two views, envying the view ... of the street if you're inside, and envying the view of the wall if you're ...
    (sci.physics.relativity)
  • Re: GOD=G_uv INVISIBLE WORLD
    ... If you're not lucky, or that ruthless, ... Think of spending a lifetime torn between those two views, envying the view ... of the street if you're inside, and envying the view of the wall if you're ...
    (sci.physics)

Loading