【发布时间】:2011-05-22 08:03:13
【问题描述】:
#!/usr/local/bin/perl
use warnings;
use 5.012;
use Text::Document;
use Text::DocumentCollection;
my $c = Text::DocumentCollection->new( file => 'coll.db' );
my $doc_one = Text::Document->new( lowercase => 0, compressed => 0 );
my $doc_two = Text::Document->new( lowercase => 0, compressed => 0 );
my $doc_three = Text::Document->new( lowercase => 0, compressed => 0 );
$doc_one->AddContent( 'foo bar biz buu muu muu' );
$doc_two->AddContent( 'foo foofoo Foo foo' );
$doc_three->AddContent( 'one two three foo foo' );
$c->Add( 'key_one', $doc_one );
$c->Add( 'key_two', $doc_two );
$c->Add( 'key_three', $doc_three );
有人可以给我看一个合理且易于理解的回调函数示例吗?
#!/usr/local/bin/perl
use warnings;
use 5.012;
use Text::Document;
use Text::DocumentCollection;
my $c = Text::DocumentCollection->NewFromDB( file => 'coll.db' );
my @result = $c->EnumerateV( \&Callback, 'the rock' );
say "@result";
sub Callback {
...
...
}
# The function Callback will be called on each element of the collection as:
# my @l = CallBack( $c, $key, $doc, $rock );
# where $rock is the second argument to Callback.
# Since $c is the first argument, the callback may be an instance method of Text::DocumentCollection.
# The final result is obtained by concatenating all the partial results (@l in the example above).
# If you do not want a result, simply return the empty list ().
【问题讨论】:
标签: perl text callback document