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

Discussion in 'Perl Misc' started by cyrusgreats@gmail.com, Oct 17, 2008.

  1. Guest

    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
    , Oct 17, 2008
    #1
    1. Advertising

  2. 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
    Jürgen Exner, Oct 18, 2008
    #2
    1. Advertising

  3. <> 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/"
    Tad J McClellan, Oct 18, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor
    Replies:
    0
    Views:
    8,822
    Victor
    Sep 1, 2004
  2. krabhi
    Replies:
    1
    Views:
    9,263
    Marco Meschieri
    Aug 9, 2006
  3. teggy
    Replies:
    0
    Views:
    804
    teggy
    May 29, 2007
  4. Stéphane Wirtel
    Replies:
    3
    Views:
    357
    Stephane Wirtel
    Jun 15, 2007
  5. Replies:
    17
    Views:
    145
    Tim Greer
    Oct 22, 2008
Loading...

Share This Page