set_uk has asked for the wisdom of the Perl Monks concerning the following question:

Using Perl::Expect to match a regex. But it isn't when it should!.

Run Perl::Expect in debug and internal mode - output below. Where it shows what it is trying to match and the regex it is using.

Matches OK when using a script to match the string and the same regex.

I have tried $Expect::Multiline_Matching = 0 and = 1 for the same effect.

spawn id(4): Does ` #00 LOGGED IN NORTEL1 12:02 3/11/2003 \r\n\r\012 +>logo\r\r\012TTY #00 LOGGED OUT NORTEL1 12:02 3/11/2003 \r\012SESSI +ON DURATION: 00:00 \r\012\r\012>' match: pattern #1: -re `LOGGED OUT.*TTY'? No. pattern #2: -re `LOGGED OUT.*>'? No.
This is the code from the Expect.PM re multiline matching.
} elsif ($pattern->[1] eq '-re') { # m// in array context promises to return an empty list # but doesn't if the pattern doesn't contain brackets (), # so we kludge around by adding an empty bracket # at the end. if ($Expect::Multiline_Matching) { @matchlist = (${*$exp}{exp_Accum} =~ m/$pattern->[2]()/m); ($match, $before, $after) = ($&, $`, $'); } else { @matchlist = (${*$exp}{exp_Accum} =~ m/$pattern->[2]()/); ($match, $before, $after) = ($&, $`, $'); }
Any pointers as to why this isn't working? Update:- Simplifying this problem out of Expect:- Why does the following not match:-
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my $String = "` #00 LOGGED IN NORTEL1 12:02 3/11/2003 \r\n\r\012>log +o\r\r\012TTY #00 LOGGED OUT NORTEL1 12:02 3/11/2003 \r\012SESSION D +URATION: 00:00 \r\012\r\012>"; my @matchlist = ($String =~ m/(.*LOGGED OUT.*>)/m); print @matchlist;
Nothing returned

20031103 Edit by jeffa: Changed title from 'Perl::Expect - Regular Expression not matching ', added strikes

Replies are listed 'Best First'.
Re: Expect.pm - Regular Expression not matching
by Abigail-II (Bishop) on Nov 03, 2003 at 12:11 UTC
    Because there is a newline ("\012") between the "LOGGED OUT" and the ">". A dot doesn't match a newline, unless you use /s (not /m) as modifier.

    Abigail

      Great thanks

Re: Expect.pm - Regular Expression not matching
by Anonymous Monk on Nov 03, 2003 at 12:31 UTC
    What is this "Perl::Expect" module ? (I can't find it anywhere)
      My mistake - the Perl Expect module.