From: Peter J. Holzer on
On 2010-07-18 10:34, Justin C <justin.1007(a)purestblue.com> wrote:
> In article <9oydnXAOU-eE5d_RnZ2dnUVZ_qmdnZ2d(a)giganews.com>, PerlTrainee wrote:
>> Okay, here is the code. Yesterday I was running the following
>> program on Window 7 Professional 64 bit. I thought the OS was the
>> culprit. I got this code from CSPAN website. So, I don't think there
>> could be something wrong with the code. I ran the same code on my
>> home computer with Window XP Professional 32 bit but got the same
>> error.
>>
>> What I don't understand is I have specified SaveParser so why it
>> wouldn't look for "AddCell" method there? Why it keeps looking for it
>> in ParseExcel?
>>
>> use strict;
>> use Spreadsheet::ParseExcel;
>> use Spreadsheet::ParseExcel::SaveParser;
>>
>> my $parser = Spreadsheet::ParseExcel->new();
>> my $workbook1 = $parser->parse('C:\readMe.xls');
>>
>> if ( !defined $workbook1 ) {
>> die $parser->error(), ".\n";
>> }
>>
>>
>> my $worksheet1 = $workbook1->worksheet('Sheet1');
>> my $parser2 = Spreadsheet::ParseExcel::SaveParser->new();
>> my $workbook2 = $parser2->parse('C:\writeMe.xls');
>
> I got your code to work by changing the above line to:
> my $workbook2 = $parser2->Parse('C:\writeMe.xls');
> (note the upper-case 'P' ^ here)
>
> I don't pretend to be an expert, but I've done some investigation and I
> find that there are two methods defined: Parse, and parse, but they are
> not the same! The one with the upper-case P is in
> Spreadsheet::ParseExcel::SaveParser, the other is in
> Spreadsheet::ParseExcel.

They could even both be spelled the same.

$parser is an object of the class 'Spreadsheet::ParseExcel', so
$parser->parse() calls Spreadsheet::ParseExcel::parse.

$parser2 is an object of the class
'Spreadsheet::ParseExcel::SaveParser', so $parser2->Parse() calls
Spreadsheet::ParseExcel::SaveParser::Parse().


> I use modules in a lot of what I code, but when they are like this I
> don't really understand what is going on. I mean, is S::PE::SP dependant
> on S::PE? Could ...SaveParser be installed without S::PE?

Maybe. It depends on how S::PE::SP is written. The documentation of
S::PE::SP should answer your questions. If it doesn't mention S:PE at
all, then S::PE::SP is probably completely independent of S::PE.

> If I "use
> S::PE::SP" does S::PE automatically get "used" as well?

No. S::PE::SP may use S::PE, but if it does, any symbols exported by
S::PE are only imported into S::PE::SP, not into your current package.

Note that in object-oriented Perl, symbols are not usually exported:
Instead the full class name is used for class methods like new, and
instance methods are referenced via the object anyway. So if you use
class A and class A uses class B, you can use class B just as if you had
used it yourself.

hp