Subject: | Expect.pm 1.21 inconsistent regexp/non-regexp pattern matching |
Date: | Fri, 07 May 2010 16:25:31 -0600 |
To: | bug-Expect [...] rt.cpan.org |
From: | roy [...] Level3.net |
In the perl documentation for Expect.pm 1.21, I see:
Changed from older versions is the regular expression handling. By
default now all strings passed to expect() are treated as
literals. To match a regular expression pass ?-re? as a parameter in
front of the pattern you want to match as a regexp.
Example:
$object->expect(15, 'match me exactly','-re','match\s+me\s+exactly');
This change makes it possible to match literals and regular
expressions in the same expect() call.
But the behavior I observe is that if the pattern is passed directly
it is treated literally, but if it is passed inside a ref to an anonymous
array it is treated as a regexp by default.
Is that the desired behavior ?
See example script below. If the pattern in the second expect
clause is removed from the anon array it matches also.
Thanks !
- roy -
roy alcala
roy@host%cat /tmp/test.sh
#!/bin/sh
echo "(foo)foo"
echo "(foo)foo"
sleep 10
roy@host%cat /tmp/test.pl
#!/usr/bin/perl
use Expect;
my $exp = Expect->spawn("test.sh") || die "Can't spawn test.sh\n";
$exp->expect(2,
['timeout', sub {print STDERR "timed out in first expect clause\n";exit(0);}],
"(foo)foo" );
print "successfully matched in first expect clause\n";
$exp->expect(2,
['timeout', sub {print STDERR "timed out in second expect clause\n";exit(0);}],
["(foo)foo"] );
print "successfully matched in second expect clause\n";
roy@host%/tmp/test.pl
(foo)foo
(foo)foo
successfully matched in first expect clause
timed out in second expect clause