CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I Need a Programmer for Freelance Work:
Multi line file pipe delimiter parsing

 



iammankani
New User

Jan 23, 2014, 12:11 PM

Post #1 of 4 (23432 views)
Multi line file pipe delimiter parsing Quote | Reply | Private Reply

The code should be written in Perl should be commented appropriately. The solution should be executable, portable and should not have any undefined functions. Use of standard libraries is fine.
The solution will be judged on efficiency, portability, readability and completeness.

The BANK keeps track of the customer spending behavior by categorizing the purchases into pre-defined categories like groceries, entertainment and fuel. There are no other categories to consider for this task
The log recorded by the software is in the following format:
Customer name|category|amount
A reference file has been provided below to test out the code.

Write a program/script to parse this information and
1. Generate a report(output file) total amount spent by each customer
2. Generate a report (output file) listing their spending in each category
3. Generate a report (output file) by sorting the list of customers based on highest spenders in each category (groceries, fuel, tobacco-liquor)

Here an example of a log file.

Example:

Veena |groceries|$1.75
Tim|entertainment$5.00
Jane|groceries|$5.50
Vinh|fuel|$4.75
Jane|entertainment|$8.70
Vinh|fuel|$60.90
Tim|entertainment|$12.80
Veena|fuel|$55
Tim|groceries|$15

Sample output for first question should look something like this:

Total amount spent by each Customer:

Veena:$56.75
Vinh: $ 65.65
Jane: $ 14.20
Tim: $ 32.8


FishMonger
Veteran / Moderator

Jan 23, 2014, 2:07 PM

Post #2 of 4 (23425 views)
Re: [iammankani] Multi line file pipe delimiter parsing [In reply to] Quote | Reply | Private Reply

Please do not post your "question" in multiple areas. I've deleted your duplicate post.

We will not do you homework assignment but we will assist you in troubleshooting YOUR code.

Please post your script and specific question on the part that is giving you trouble. Include any/all errors and warnings that your code produces.


(This post was edited by FishMonger on Jan 23, 2014, 2:08 PM)


iammankani
New User

Jan 23, 2014, 6:41 PM

Post #3 of 4 (23407 views)
Re: [FishMonger] Multi line file pipe delimiter parsing [In reply to] Quote | Reply | Private Reply

 
Got the 1st part of the question.
Trying the 2nd part with the below
2.listing their spending in each category

while(<FILE>) {
chomp;
my ($name, $item, $price) = split /[|]/;
$price =~ s/^\$//;
foreach $name ($item){
$sum_for{$item} +=$price
}

print "$_: \$$sum_for{$_}\n" for sort keys %sum_for;
}

not able to get the output


FishMonger
Veteran / Moderator

Jan 23, 2014, 8:04 PM

Post #4 of 4 (23394 views)
Re: [iammankani] Multi line file pipe delimiter parsing [In reply to] Quote | Reply | Private Reply

What output are you getting and how does that differ from what you expect?

$item is a scalar, not an array so using it in a loop like that doesn't make any sense.

Your %sum_for hash should be constructed as a HoH (Hash of Hashes).

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives