Reputation: 29
I am a newbie to Perl programming. Currently I have a task of understanding some code.
I have to understand Perl Expect code and in this piece of code a line is there, mentioned below:
my $exp = new Expect;
$exp->spawn("su");
My understanding is line 1 tells that we create an instance of the class and line 2, create a child process.
If anyone explain me more clearly I will be really thankful to them.
Upvotes: 2
Views: 3059
Reputation: 39763
First of all, let me help you help yourself:
You are working with the Expect module here, found at CPAN:Expect.
From a strictly syntactic point of view, all you are doing is calling two methods:
my $exp = Expect->new(); #Yes, the new Expect is a shorthand version
$exp->spawn("su");
Both methods are documented at CPAN, and they indeed do what you expect (no pun intended) them to do: the first one creates an Expect object, the second one spawns a process "su" without any parameters.
Now you can probably go using the send and expect methods to send a string to the process, or wait until it asks for input. Straight from the CPAN example:
# send some string there:
$exp->send("string\n");
# then do some pattern matching with either the simple interface
$patidx = $exp->expect($timeout, @match_patterns);
Upvotes: 3