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

Hello,

I've got a curious problem. I'm using Spreadsheet::TieExcel to read and write a MS Excel file. As soon as I use Spreadsheet::TieExcel, all my print statements have a \n appended to the end of them.

This snippet:

use strict; use warnings; #NOTE: you must have Excel open for this to work. use Spreadsheet::TieExcel; print "asdf"; print "1234";
prints
asdf 1234
Commenting out the use Spreadsheet::TieExcel works as expected.
use strict; use warnings; #use Spreadsheet::TieExcel; print "asdf"; print "1234";
prints
asdf1234 as expected.

I'm using Windows XP, Activestate Perl build 811, and Spreadsheet::TieExcel version 0.73.

Thoughts? Questions? Comments?

Cheers,

Brent

-- Yeah, I'm a Delt.

Replies are listed 'Best First'.
Re: print adds \n when using Spreadsheet::TieExcel
by ikegami (Patriarch) on Apr 11, 2006 at 16:06 UTC

    I just took a peek at the source of the latest Spreadsheet::TieExcel on CPAN (0.73). It executes $\ = "\n"; $, = "\t";. It doesn't even use either of these vars, directly or indirectly, as far as I can tell.

    The workaround is to change

    use Spreadsheet::TieExcel;

    into

    BEGIN { # Prevent Spreadsheet::TieExcel from clobbering $\ and $, local ($\, $,); require Spreadsheet::TieExcel; Spreadsheet::TieExcel->import(); }
Re: print adds \n when using Spreadsheet::TieExcel
by japhy (Canon) on Apr 11, 2006 at 16:06 UTC
    You should yell at Simone Cesano (simonecesano@libero.it), the author. He set $\ and $, without local()izing them.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart