I playing with
Gearman::Client and below are my codes. Basically what I wanted to do is to send a string from the client and have the worker split them and return two strings.
#!/usr/bin/perl
# worker.pl
use strict;
use Gearman::Worker;
my $worker = Gearman::Worker->new();
$worker->job_servers( '127.0.0.1:4730' );
$worker->register_function( 'split_it',
\&my_split_function );
$worker->work() while 1;
sub my_split_function {
my $string = $_[0]->arg;
my @new_string = split( ',', $string );
return \@new_string;
}
-------
#!/usr/bin/perl
# client.pl
use strict;
use Gearman::Client;
my $client = Gearman::Client->new();
$client->job_servers('127.0.0.1:4730');
my $result = $client->do_task( 'split_it', 'abc,def' );
print "Split: @$result\n";
When I run the client.pl, it will give an error output on the worker.pl something like
Not a SCALAR reference at
/usr/local/share/perl/5.8.8/Gearman/Worker.pm line 365.
Does this mean that it is expecting the worker.pl to return a scalar reference? Since I'm trying to return an array reference, then it is failing?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.