Ram Prasad wrote:
I want to find if a regex matched what exactly matched

to reproduce this

------------------
my @x;
$x[0] = 'chi+ld*';
$x[1] = '\sjoke';

$_=getinput();               # for test assume $_="This is a joke";

if(/($x[0]|$x[1])/){
       print "Matched '$1' \n";
}
-----------------

I want to know if $x[0] matched or $x[1] matched
What is the most efficient way of doing this ?

"Efficient", in what sense?

Anyway, you can surround both scalars with capturing parentheses.

    my @x = ('chi+ld*', '\sjoke');
    $_ = 'This is a joke';
    if ( /($x[0])|($x[1])/ ) {
        print '$x[', $1 ? '0' : '1', "] matched.\n";
    }

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to