Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Need help on AoH or array or any other help I can get for this task

Reply
Thread Tools

Need help on AoH or array or any other help I can get for this task

 
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      10-17-2008
Hello good people out there. I need to write a perl script that will
parse the log and generate the following output:
a flat text file in the following format: customer_name|
product_category|item_description|cost
An example log file could be:
Pedro|groceries|apple|1.42
Nitin|tobacco|cigarettes|15.00
Susie|groceries|cereal|5.50
Susie|groceries|milk|4.75
Susie|tobacco|cigarettes|15.00
Susie|fuel|gasoline|44.90
Pedro|fuel|propane|9.60

1.A report of the total revenue resulting from each customer.
2.A report for each customer showing how much of their spending went
to each category.
With the above example log file, the script should output should be
something like:
Total Revenue:
Pedro - $11.02
Nitin - $15.00
Susie - $70.15

Purchases by Pedro:
groceries - $1.42
fuel - $9.60

Purchases by Nitin:
tobacco - $15.00

Purchases by Susie:
groceries - $10.25
fuel - $44.90
tobacco - $15.00

#!/usr/bin/perl
use strict;

my $file = "inventory";
open (FILE, $file) || die ("Could not open file. $!");

foreach my $line (FILE) {
my ($customer_name, $product_cat, $item_desc, $cost) = split("|",
$line);


what should I do here
Any help will be appreciated...million thanks in advance
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-17-2008
wrote:
>Hello good people out there. I need to write a perl script that will

[...]
>foreach my $line (FILE) {
> my ($customer_name, $product_cat, $item_desc, $cost) = split("|",
>$line);
>
>
>what should I do here


Ask the person who assigned the home work to you, maybe?

jue
 
Reply With Quote
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      10-18-2008
<> wrote:

> foreach my $line (FILE) {

^^^^
> my ($customer_name, $product_cat, $item_desc, $cost) = split("|",
> $line);
>
>
> what should I do here



You should first get the code that you do have to work...


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help on AoH or array or any other think that might help! cyrusgreats@gmail.com Perl Misc 17 10-22-2008 03:06 AM
[Rake] call a task of a namespace from an other task. Stéphane Wirtel Ruby 3 06-15-2007 06:52 AM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Maven using ANT plugin for SCP task : Embedded error: Could not create task or type of type: scp. krabhi Java 1 08-09-2006 04:19 PM
Re: Problem in ant replace task and replaceregexp task to update xml Victor Java 0 09-01-2004 03:58 AM



Advertisments