use warnings; use strict; my (@fruitname, %fruit, %totals); my $tab=9; open DATA, "data.txt"; @fruitname = split /[,\s]+/ => <DATA>; #@fruit{ @fruitname } = undef;
while ( <DATA> ) { my @values = split /[,\s]+/; # => $_ ; for (my $x=0; $x<=$#values; $x++) { push @{ $fruit{$fruitname[$x]} } => $values[$x]; } } foreach my $fruit( sort keys %fruit ) { print "$fruit\n"; my ($x, $total); foreach my $val( @{ $fruit{$fruit} } ) { print "\tDay ", ++$x, ":\t$val\n"; $total += $val; } print "\tTotal:\t$total\n"; } my $x; foreach my $val( @{ $fruit{$fruitname[0]} } ) { print "Day ", ++$x, ":\n"; my $total; foreach my $fruit( sort keys %fruit ) { print "\t$fruit\t"; print "\t" if length($fruit)<$tab; print "$fruit{$fruit}[$x-1]\n"; $totals{$fruit} += $fruit{$fruit}[$x-1]; $total += $fruit{$fruit}[$x-1]; } print "\tTotal\t\t$total\n"; } print "Totals:\n"; my $total; foreach my $fruit ( sort keys %totals ) { print "\t$fruit\t"; print "\t" if length($fruit)<$tab; print "$totals{$fruit}\n"; $total += $totals{$fruit}; } print "\tTotal\t\t$total\n"; -----Original Message----- From: Mark. [mailto:[EMAIL PROTECTED]] Sent: Monday, April 15, 2002 5:02 AM To: drieux Cc: [EMAIL PROTECTED] Subject: Re: splitting / regex / trend etc Exactly what I'm looking for! (Amazing stuff) Out of intrest, if I wanted to look at the exact no. sold ie. get output like: apples, 4, 3 and 0 where would I start looking? Many many thanks! Mark On Friday 12 April 2002 15:55, you wrote: > On Friday, April 12, 2002, at 03:56 , Mark. wrote: > > > apples, melon, oranges, pears, coconut, lemons, grapefruit > > 4, 3, 2, 7, 1, 4, 0 > > 3, 1, 4, 4, 0, 0, 1 > > 0, 4, 0, 0, 4, 5, 0 > > http://www.wetware.com/drieux/CS/lang/Perl/Beginners/FruitPickFromCVS.txt > > offers an illustration about how this problem can be solved. > > To test the sub get_store_hash - I of course pass in the file > to be parsed - expecting to get a hash back. > > hence how some ever one wished to tie the store data file to the > hash is up to the user.... and since one can index into the returned > hash knowing > > $count_o_fruit = $retHash{ $fruit } ; > > the rest is merely option picking for command line parsing... > and > > "so given <N> hashes of arbitrary size how does one pick > out the common values...." > > ciao > drieux > > --- > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]