perl_sunil has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have this line in my script:
print FHL $time_date;
Now, $time_date is "200802251655", but the output csv file cuts it down to "2.00802E+11".
Is there any way I can ensure that it prints the entire thing in the csv file. I tried putting it in quotes, it didn't work.
Thanks in advance

Replies are listed 'Best First'.
Re: Printing long number into file
by Corion (Patriarch) on Oct 21, 2008 at 06:33 UTC

    When producing output for Excel, consider Spreadsheet::WriteExcel. I've produced CSV / TSV files for a long time, but Spreadsheet::WriteExcel makes it convenient to produce real Excel files instead.

Re: Printing long number into file
by ccn (Vicar) on Oct 21, 2008 at 06:09 UTC
    The Perl itself doesn't modify numbers. It can happens when third party programm reinterprets csv file. You can try to print ' character before a number to force Excel read it as text value.
Re: Printing long number into file
by jvector (Friar) on Oct 21, 2008 at 11:47 UTC
    As the others have said, it's not that your value in the CSV file is "wrong"; rather it is that Excel is choosing to apply its own formatting to the cell in which you want it to put the value 200802251655. ( OK, I am making an assumption here about your situation.)

    I had a situation where I was doing a very similar thing, and my consumers (who were picking up the CSV file in Internet Explorer) were reporting this problem. They did not want to have to go into Excel's "Format Cell..." dialogue. Eventually I changed the format of the generated date/timestamp in the CSV file to "2008-02-25 16:55" (complete with the quotes) , Excel was happy, users were happy, I was happy ;-)

    This signature will be ready by Christmas
Re: Printing long number into file
by ikegami (Patriarch) on Oct 21, 2008 at 06:20 UTC
    >perl -le"$time_date=200802251655; print STDOUT $time_date;" 200802251655

    I can't reproduce your results. Please provide more info.

Re: Printing long number into file
by tinita (Parson) on Oct 21, 2008 at 17:33 UTC
    additionally to the other answers: if we are talking about excel/openoffice here, in the import-dialogue you can choose the type of the fields, so here you'd have to choose Text'.