Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: CSV or HTML?

by furry_marmot (Pilgrim)
on Jan 19, 2012 at 00:48 UTC ( #948653=note: print w/ replies, xml ) Need Help??


in reply to CSV or HTML?

For CSV, use Text::CSV_XS. It will take care of all the CSV creation. I assume you have Excel or OpenOffice, so you can load it in and print it as you like. If you have something else in mind, you might consider saying it instead of leaving us to guess.


Comment on Re: CSV or HTML?
Re^2: CSV or HTML?
by jms53 (Monk) on Jan 19, 2012 at 07:17 UTC

    Thats interesting. All the CSV modules I found were meant to read a CSV in PERL as opposed to writing one.

    I am using OpenOffice, and the issue was that it was adding the single quote to numbers, therefore making it impossible to format the column as "number".

    I'll be sure to look up that module, thanks!

      I've seen that complaint before, which is odd because the docs clearly tell you how to write a CSV, as well. The first sentence of the description says so specifically. The functions you want are combine (into a CSV string) or, more likely, print (combine and then print to a filehandle).

      Here's a simple example:

      @headers = ( "First", "Second", "Third", "Fourth" ); @cols = ( "I'm text", 12, # <--Number "", "That was a blank" ); my $csv = Text::CSV_XS->new; open my $fh, ">Output.csv" or die $!; $csv->print($fh, @headers); # Prints with \n by default $csv->print($fh, @cols); # Use something like # $csv->print($fh, @$_) for @rows # for an array of data.

      Output.csv should look like this:

      "First","Second","Third","Fourth" "I'm text",12,,"That was a blank"

      Cheers!

      --marmot UPDATED: for clarity and to correct a typo.
        cheers!

        I ended up forcing the ' character both before and after the numbers.

        I'll be sure to try this solution, as currently it's taking me longer to convert the results to numbers, than the actual calculation process.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-07-28 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls