Subject: | Problem with "require Spreadsheet::Read" (instead of "use ...") |
Try the following (assuming you also have e.g. Spreadsheet::ParseExcel
installed)
sub foo
{
require Spreadsheet::Read;
Spreadsheet::Read::ReadData("some.xls", parser => "xls");
}
foo(42);
which results in:
Parser for XLS is not installed
(if you "use ..." instead of "require ..." it works).
If I Dump(\%can) just after line 57 of Spreadsheet/Read.pm I get
$VAR1 = {
'sc' => 'Spreadsheet::Read',
'csv' => 0,
'sxc' => 0,
'xlsx' => 0,
'xls' => 0,
'ios' => 0,
'prl' => 0,
'ods' => 0
};
The reason is the @_ on line 55:
eval "require $mod; \@_ or \$can{\$flag} = '$mod'";
For "use ..." this line is executed in top level context, i.e. @_=().
But for "require ..." called inside a sub with arguments,
@_ in scalar context evaluates to true and the assignment
to can{...} isn't executed.
Actually I think @_ here is a thinko, the line should read
eval "require $mod; \$can{\$flag} = '$mod'";
(if the require fails, it will die and the assignment isn't reached).
Cheers, Roderich