develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991110.003] another matching finding by pcre author

Thread Previous
From:
Greg Bacon
Date:
November 10, 1999 07:01
Subject:
Re: [ID 19991110.003] another matching finding by pcre author
Message ID:
199911101507.JAA16035@ruby.itsc.uah.edu
In message <199911101300.PAA16873@mimosa.hut.fi>,
    Jarkko Hietaniemi writes:

: One more from PCRE (ftp://ftp.cus.cam.ac.uk/pub/software/programs/pcre/)
: author Philip Hazel.  If this (rightly) fails to match
: 
: ./perl -wle '"a" =~ /^(a)?a$/;print $1'
: Use of uninitialized value at -e line 1.

It does match, but greed makes the ? give up its a, leaving $1 empty:

    #! /usr/bin/perl -w

    use strict;

    print q{"a" =~ /^(a)?a$/}, "\n";
    if ("a" =~ /^(a)?a$/) {
        print "\$1 = `", defined $1 ? $1 : "<undef>", "'\n";
    }
    else {
        print "No match.\n";
    }
    [9:05] ruby% ./try
    "a" =~ /^(a)?a$/
    $1 = `<undef>'

: why does this match?
: 
: ./perl -wle '"a" =~ /^(a)?(?(1)a|b)+$/;print $1'
: a

That looks like a bug to me.  It should match, but $1 should be empty
in that case.

Greg

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About