Perl::expect script error

R

ruud

I'm writing a script that can post to my newsserver.

#!/usr/bin/perl
use Expect;
use warnings;
use strict;

my $post = "post";
my $hallo = "200";
my $quit = "quit";
my $conn;

$conn -> spawn ("news.nntpserver.com:119");
$conn -> expect ("$hallo");
print "$post\n";

But i get this error:
Can't call method "spawn" on an undefined value at ./p line 11.

What is wrong with this expect script ?
 
A

A. Sinan Unur

I'm writing a script that can post to my newsserver.

#!/usr/bin/perl
use Expect;
use warnings;
use strict;



my $post = "post";
my $hallo = "200";
my $quit = "quit";
my $conn;



$conn -> spawn ("news.nntpserver.com:119");
$conn -> expect ("$hallo");
print "$post\n";

But i get this error:
Can't call method "spawn" on an undefined value at ./p line 11.

What is wrong with this expect script ?

Exactly what perl tells you.

It seems like you haven't even read the documentation for Expect.pm.

Expect->spawn($command, @parameters) or
$object->spawn($command, @parameters) or
new Expect ($command, @parameters)

Forks and execs $command. Returns an Expect object upon success
or undef if the fork was unsuccessful or the command could not
be found. spawn() passes its parameters unchanged to Perls
exec(), so look there for detailed semantics.

$conn is not defined at the moment when you call the spawn method on it.
The interface specifies:

my $conn = Expect->new($command, @parameters);

Which brings us to the second issue: The domain name of your news server
is not a command that can be executed on your machine. I guess you could
spawn a telnet session with the news server but why you would bother
with such a cumbersome method is beyond me and I can't really figure out
why you think Expect is a good tool to interact with a news server.

CPAN contains an assortment of NNTP related modules. While I haven't
used either of them, Net::NNTP and Net::NNTP::Client would be the first
modules I would have looked at had I wanted NNTP functionality.

Sinan.
 
R

ruud

A. Sinan Unur said:
Expect->spawn($command, @parameters) or
$object->spawn($command, @parameters) or
new Expect ($command, @parameters)

Forks and execs $command. Returns an Expect object upon success
or undef if the fork was unsuccessful or the command could not
be found. spawn() passes its parameters unchanged to Perls
exec(), so look there for detailed semantics.

$conn is not defined at the moment when you call the spawn method on it.
The interface specifies:

my $conn = Expect->new($command, @parameters);

Thank you for pointing me in the good direction.
It's working like a charm now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top