Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Creating Reports

by sschneid (Deacon)
on Jul 26, 2004 at 19:50 UTC ( [id://377544]=note: print w/replies, xml ) Need Help??


in reply to Creating Reports

Do you have anything you've written in an attempt to do this yet? Sounds a bit like homework, so here are some pointers to get you started:

First: open and close will allow you to read files.

split will allow you to seperate fields per line from a CSV file.

-s.

Replies are listed 'Best First'.
Re^2: Creating Reports
by dragonchild (Archbishop) on Jul 26, 2004 at 20:08 UTC
    Never EVER suggest using split to parse a CSV file. That is an extremely reckless and stupid thing to do. Text::CSV, Text::CSV_XS, Text::xSV, and DBD::CSV and all extremely good solutions. Most are even PurePerl, so loading them isn't an issue on any platform.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Never EVER suggest using split to parse a CSV file. That is an extremely reckless and stupid thing to do.

      I have to say that I think that is somewhat overstating the case. I can't see any problem whatsoever with processing character separated data with split when the data is from a known source and is consistent in its format - say:

      FOO,1,2 BAR,2,3 BARG,29,38
      after all we do have split for a reason. On the other hand I think it would be true that if one were to try and process the CSV output of, say, MS Excel with split one is likely to be disappointed with the results, but I wouldn't go so far as you have.

      /J\

      Just checked out the page on DBD::CSV and that looks like a darn good place to start, thank you
      Text::CSV, Text::CSV_XS, Text::xSV, and DBD::CSV and all extremely good solutions

      So is Text::ParseWords. And that's a standard Perl module.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Are you saying that Text::ParseWords can handle every case that Text::xSV can? Why hasn't anyone ever mentioned this module? As in I've read nearly every node to do with parsing on this site for the past 3 years and I've never heard of it.

        Would I be correct in thinking that the following are equivalent?

        use Text::ParseWords; my @lines = do { open FH, $filename; <FH> }; foreach my $line (@lines) { my @parsed_out = quotewords(',', undef, $line); # Do stuff here } --------------- use Text::CSV; my $parser = Text::CSV->new; my @lines = do { open FH, $filename; <FH> }; foreach my $line (@lines) { $parser->parse( $line ); my @parsed_out = $parser->fields; # Do stuff here } --------------- use Text::xSV; my $parser = Text::xSV->new; $parser->open_file( $filename ); while (my $parsed_out = $parser->get_row) { # Do stuff here }

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re^2: Creating Reports
by George_Smiley (Initiate) on Jul 26, 2004 at 20:01 UTC
    nope not homework, I know how to manipulate the files just fine, I just don't know how to create totals on fields that are not predetermined.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377544]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found