using Spreadsheet::ParseExcel problems

J

Jeff

Hi-

Im trying to use this the Spreadsheet::parseExcel module and
having difficulty getting started. When I use the examples Ive
seen I get the following error:

Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
5.10.0/Spreadsheet/ParseExcel.pm line 178.

I havent coded much since I was trying to figure out how to use it,
my code is just:

#!/usr/bin/perl -w

use Spreadsheet::parseExcel;

my $parse = new Spreadsheet::parseExcel->new() || die "ERROR creating
new object";
exit 0

I just downloaded the module today so it should be the latest.
Im running perl 5.10.0 on Linux fedora core.

Any suggestions as to what to check?
Thanks
 
J

Justin C

Hi-

Im trying to use this the Spreadsheet::parseExcel module and
having difficulty getting started. When I use the examples Ive
seen I get the following error:

Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
5.10.0/Spreadsheet/ParseExcel.pm line 178.

I havent coded much since I was trying to figure out how to use it,
my code is just:

#!/usr/bin/perl -w

use Spreadsheet::parseExcel;

my $parse = new Spreadsheet::parseExcel->new() || die "ERROR creating
new object";
exit 0

I just downloaded the module today so it should be the latest.
Im running perl 5.10.0 on Linux fedora core.

Any suggestions as to what to check?
Thanks

You've got too many 'new's on the "my $parse" line. Instead try:

my $parse = Spreadsheet::parseExcel->new();

I think the "or die" bit is redundant too, if it doesn't succeed then
there will be an error anyway. The module documentation has an
alternative based on the fact that you're also going to want an Excel
workbook to parse:

my $parser = Spreadsheet::parseExcel->new();
my $workbook = $parser->parse('Book1.xls');

if ( !defined $workbook ) {
die $parser->error(), ".\n";
}

I don't know what documentation you are reading, but take a look at
what's here:
<URL:http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.57/lib/Spreadsheet/ParseExcel.pm>.

Justin.
 
S

Steve M

Hi-

Im trying to use this the Spreadsheet::parseExcel module and
having difficulty getting started. When I use the examples Ive
seen I get the following error:

Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
5.10.0/Spreadsheet/ParseExcel.pm line 178.

I havent coded much since I was trying to figure out how to use it,
my code is just:

#!/usr/bin/perl -w

use Spreadsheet::parseExcel;

my $parse = new Spreadsheet::parseExcel->new() || die "ERROR creating
^^^^ ???
new object";
exit 0

I just downloaded the module today so it should be the latest.
Im running perl 5.10.0 on Linux fedora core.

Any suggestions as to what to check?
Thanks

use Spreadsheet::parseExcel;

my $file = '/path/to/file.xls';

my $parser = Spreadsheet::parseExcel->new();
my $workbook = $parser->Parse($file);
my $worksheet = $workbook->Worksheet(0); # assume first sheet

hth,

\s
 
C

C.DeRykus

The additional 'new' results in

my $parse = Spreadsheet::parseExcel->new->new

which causes perl to die:

perl -MSpreadsheet::parseExcel -e '$p=Spreadsheet::parseExcel
->new->new'
Attempt to bless into a reference at -e line 1.
...

my $parse = Spreadsheet::parseExcel->new();

I think the "or die" bit is redundant too, if it doesn't succeed
...

Or you may want to wrap the call in an eval {} for more
control...

my $parse = eval { Spreadsheet::parseExcel->new(); };
die "error: ... $@" if $@;
 
C

C.DeRykus

Quoth "C.DeRykus" <[email protected]>:





It's always safer to use the return value of eval, rather than testing
$@:

    my $parse = eval { Spreadsheet::parseExcel->new }
        or die "error: ... $@";

If a signal comes in between the 'eval' and the 'if', or if S::pE->new
leaves something on the stack with a destructor, and that code clears
$@, the first construction will miss the error. The second will still
see the wrong value for $@, but that's better than not catching the
error at all.

Yes, that's true although, even if the error's not caught,
the problem will be exposed quickly when a method's called
on the undefined $parse object. But, getting the error much
earlier at the scene of the crime is certainly preferable
even with the remote possibility of seeing a bogus $@.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top