"Beginner" schreef: > On 22 Nov 2006 at 15:14, Beginner wrote:
>> The data looks like it is suited to a hash but GD::lines wants the >> data passed to in as arrays references ([EMAIL PROTECTED]). That is one array >> with all the "ancode_n" and foreach code, an array of all the yearly >> values. I have managed to get my data into this type of structure >> >> 'ADV ' => [ >> '117216', >> '104776', >> ] >> 'BAP ' => [ >> '0', >> '270', >> ], > > I managed to do it with this: > > my (@data,@leg); > > foreach my $code (keys %values) { > push @leg,$code; > my @temparray; > for (my $i = 0;$i <$no_years;++$i) { > push @temparray, $values{$code}[$i]; > } > my @foo = reverse @temparray; > push @data,[EMAIL PROTECTED]; > } Maybe this helps: #!/usr/bin/perl use warnings ; use strict ; use Data::Dumper; my ($an, @ancodes, %yrs, %values) ; for (<DATA>) { if (/"ancode_(\d+)" = "(\w{3}) "$/) { $an = $2 ; push @ancodes, $an ; } elsif (/^"${an}_(\d{4})" = "([^"]*?[^" ]) *"$/) { $yrs{ $1 } ++ ; $values{ $an }{ $1 } = $2 ; } } { local $\ = "\n" ; print Dumper( [EMAIL PROTECTED] ) ; print Dumper( \%yrs ) ; print Dumper( \%values ) ; } for $an (sort @ancodes) { for my $y (sort keys %yrs) { print "$an,$y,", $values{ $an }{ $y }, "\n" ; } } __DATA__ "ancode_1" = "ADV " "ADV_2006" = "117216 " "ADV_2005" = "104776 " "ancode_2" = "BAP " "BAP_2006" = "0 " "BAP_2005" = "270 " "ancode_3" = "BOO " "BOO_2006" = "746854 " "BOO_2005" = "673151 " "ancode_4" = "BUS " "BUS_2006" = "0 " "BUS_2005" = "2476 " "ancode_5" = "COM " "COM_2006" = "87787 " "COM_2005" = "97009 " -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>