Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: CSV or HTML?

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

in reply to Re^2: CSV or HTML?
in thread CSV or HTML?

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"


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

Comment on Re^3: CSV or HTML?
Select or Download Code
Replies are listed 'Best First'.
Re^4: CSV or HTML?
by jms53 (Monk) on Jan 20, 2012 at 13:47 UTC

    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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2016-02-12 04:32 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (388 votes), past polls