Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Expect multiple values

use strict;
use warnings;

my $x = rand();
if ($x < 0.3) {
    print "abc\n";
} elsif ($x < 0.6) {
    print "def\n";
} else {
    print "xyz\n";
}
use strict;
use warnings;

use Test::More tests => 1;
use Expect;


my $exp   = Expect->new( "$^X examples/expect/random.pl" );
my $val;
$exp->expect(
    2,
    [ "abc" => sub { $val = 1; } ],
    [ "def" => sub { $val = 1; } ],
);
ok $val;