develooper Front page | perl.beginners | Postings from April 2012

Re: Merge two files with similar column entries

Thread Previous
From:
Jim Gibson
Date:
April 8, 2012 17:44
Subject:
Re: Merge two files with similar column entries
Message ID:
p06240800cba7de6ebb6a@[192.168.1.3]
At 3:33 AM +0530 4/9/12, S Pratap Singh wrote:
>Hi ,
>
>I have few files which contains user name and data transfer rate in MBs and
>this data is collected for year and for each month report is saved in 12
>different files I have to merge all the files to prepare the final report
>Files are as below


First, write a program that successfully opens and reads all of the 
files. Derive the month from the file name or the file name from the 
month, if they are not the same, as you will need both. Assign the 
month name to a variable, e.g., $month.

Read the files, one line at a time. Identify the lines that have data 
in them. Extract the user name into one variable, e.g., $user, and 
the data transferred into another variable, e.g. $transferred.

Store the data in a hash-of-hashes, e.g. %data_transferred, this way:

$data_transferred{$user}{$month} = $transferred;

When you have read all of the files, you can iterate through the hash 
and print your report. If an entry does not exist, print "Not 
available"

If you get stuck, post your program here and someone will be able to help you.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About