changma_ha has asked for the wisdom of the Perl Monks concerning the following question:
Hi all i am trying to solve a problem for a long time. where i have data table in a text file like
Apple Grape 100 Ginger Fry 200 Apple Grape 80 Ginger Banana 800 Ginger Fry 150 Ginger Banana 45
I want my output to be like this, where the duplicate data values are added
Apple Grape 180 Ginger Fry 350 Ginger Banana 845
I am trying to do it using array of arrays but not able to proceed much.here is my code
Is there other way which will be easier to do? plz help..thaanks in advance <#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my @AoA; open (my $fh ,"<","C:/excl7.txt") or die "Can't open the file"; while (<$fh>){ #chomp ($line); push @AoA,[split]; } foreach my $i (@AoA){ #** how do i compare the array data?... if (@{$i print "@$i\n"; } #my @new =shift (@AoA); #print $AoA[1][0]; #print Dumper \@AoA;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Adding the duplicate data using arrays
by Ratazong (Monsignor) on Aug 11, 2010 at 07:31 UTC | |
Re: Adding the duplicate data using arrays
by biohisham (Priest) on Aug 11, 2010 at 07:49 UTC | |
| |
Re: Adding the duplicate data using arrays
by wwe (Friar) on Aug 11, 2010 at 07:46 UTC |
Back to
Seekers of Perl Wisdom