Perl Expect bindings – Simple example

Hello World file (hello.pl)

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics; print "-----------\n",
 "Hello World\n",
 "-----------\n";

Test Perl file with expect bindings (test.pl)

#!/usr/bin/perl
use strict;
 use warnings;
 use diagnostics;
use Expect;
my $timeout=5;
foreach my $i (1..20)
 {
 my $exp = Expect->spawn("./hello.pl")
 or die "Unexpected error : $!\n";
$exp->expect($timeout);
 }

Perl – system load

To find the system load use the following perl snippet :

1) System load of last one minute :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f1');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f1');

2) System load of last 5 minutes :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f2');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f2');

3) System load of last 15 minutes :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f3');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f3');

Gearman – Can’t call method “syswrite” on an undefined value at /usr/local/share/perl/5.10.1/Gearman/Taskset.pm line 202.

If you get the following error while running the client code :

Can’t call method “syswrite” on an undefined value at /usr/local/share/perl/5.10.1/Gearman/Taskset.pm line 202.

… then change this

$client->job_servers(‘127.0.0.1’);
to
$client->job_servers(‘127.0.0.1:4730’);
thats it !
:)