Gunnar Hjalmarsson wrote:
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";

          print "\$x[", @- - 1, "] matched.\n"

    }


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

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


Reply via email to