AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

How to pass multiple parameters to subroutine in RS in perl
 
 

I have written a reply subroutine with Perl. It is ok when it takes input as a single keyword but I need multiple keywords to be taken as input how do I pass that as a parameter. My RS code in Perl has

+ what is *
- <call>getanswer <star></call>

+ when is *
- <call>getanswer <star></call>

> object getanswer perl
  my ($self, $args) = @_;
use MongoDB;
sub answer_get {
do something…....
}
my $get_answer = answer_get(“xxxx”, “xxxx”, “$args”);

if ( defined($get_answer) ){
return $get_answer;
}
else {
return "No";
}

< object
Here when question is what <star> tag will pass on keyword. With <star> keyword I need another keyword as an input to getanswer subroutine. Suppose I ask what is AI. I need to pass AI (which is there in <star> tag) and also need context of question so need to pass another keyword what.
How do I do it here. When I try to elaborate @_ it is giving error.

my ($self, $args, $args1) = @_;

Use of uninitialized value $args1

 

 
  [ # 1 ]

Works fine for me!!


>object webservice perl
my ($rs, @args) = @_;
my $remote = IO::Socket::INET->new(Proto=>“tcp”,
                        PeerAddr=>“localhost”,
                        Reuse=>1,
                        PeerPort=>45000);
.
.               
print $remote “@args\n”;
.
.
< object


.
.

 

 
  [ # 2 ]

One of the problems is that the args to the object macro are space-separated so if you had multiple words, each word is its own array item in the @args.

The JavaScript version got shell-style quoting support, so a “quoted string with spaces” comes in as a single array item instead of being broken into many. But none of the other versions gained that feature because they’re not as popular and nobody demanded it (actually the JS feature was contributed by an outside developer!)

So two ideas:

1. If you’d like, you could update the Perl RiveScript module to support quoted shell-style arguments like the JS version and send a pull request so it benefits others.
2. What I’d found myself doing sometimes is to just re-parse the args inside my function. May be simpler for you but doesn’t fix the problem inside RiveScript.

my ($rs, @args) = @_;
my $message join " ", @args;  # join them back together
# and then do what you need. regexp parse it or whatever 
 

 
  login or register to react