Skip Menu |
 

This queue is for tickets about the Expect CPAN distribution.

Report information
The Basics
Id: 57287
Status: resolved
Priority: 0/
Queue: Expect

People
Owner: Nobody in particular
Requestors: roy [...] Level3.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Download (untitled) / with headers
text/plain 1.4k
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
Download (untitled) / with headers
text/plain 1.2k
Am Fr 07. Mai 2010, 18:26:02, roy@Level3.net schrieb: Show quoted text
> > 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 ?
Yes, that's the desired behaviour. There are two "styles": one with callbacks where you pass your pattern and the callback as an array ref in brackets. Here the patterns are by default taken to be regexps. The other (old) style is where you just give a list of patterns and get back the index which pattern in the list matched. Here the patterns are interpreted iterally by default. Hope this helps, Roland -- RGiersig@cpan.org


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.