2011-12-07 20 views
0

我想在Perl中使用Text::DocumentCollection。我希望能夠從文件句柄中讀取文本,並從該文本構建文檔集合,但我不確定這是否是此模塊的預期用途。在Perl中添加一個帶有Text :: DocumentCollection的文檔

該文檔指的是添加一個「文檔」,但我不確定文檔是什麼。它是一個文件嗎?它可以是變量中的字符串嗎?

下面的代碼返回一個錯誤:

use Text::DocumentCollection; 

my $c = Text::DocumentCollection->new(file => 'test.db'); 
$doc = 'test_doc'; 
$c->Add('doc1', $doc); 

錯誤:

 
Can't locate object method "WriteToString" via package "test_doc" 
(perhaps you forgot to load "test_doc"?) at ...DocumentCollection.pm line 62. 

是什麼意思的 「負荷」,什麼是 「包」?

回答

2

從包含在CPAN分發中的測試看來,Add方法的第二個參數應該是對對象的引用,而不是簡單的字符串。

例如,從t/collection.t

use Text::DocumentCollection; 
use Text::Document; 

my $d1 = Text::Document->new(); 
$d1->AddContent(' danelle folta michelle pfeiffer '); 

my $d2 = Text::Document->new(); 
$d2->AddContent(' danelle folta mary elizabeth mastrantonio '); 

my $c = Text::DocumentCollection->new(file => 't/collection.db'); 

$c->Add('a', $d1); 
$c->Add('b', $d2); 
+1

謝謝,我不知道在看的例子的測試信息。很有幫助! – itzy

相關問題