in reply to Re: Regular Expression
in thread Regular Expression

my ($Rkey_id, $Rkey_val) = $line =~ /Id="(.*?)".*?>(.*?)</) above code return correct result but when i try this,
my $line = "AAA:BBB:CCC"; my $var = $line =~ /.*?:(\w+):.*?$/; print "$var\n";
If i am just interested in "BBB", above code returning 1 rather than BBB, Could any one guide me why? and how can I achieve this? Please. Cheers

Replies are listed 'Best First'.
Re^3: Regular Expression
by NetWallah (Canon) on Jun 24, 2009 at 05:01 UTC
    It is all in the context.

    Your assignment to "my $var" is in a scalar context.

    The result of the regular expression is a single item in a list context.

    You can get the desired result by:

    my ($var) = $line =~ /.*?:(\w+):.*?$/; # Declare $var in a List contex +t.

         Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)