Not possible, $2 is always undefined.
What will the regular expression?#!/usr/bin/perl -- use strict; use warnings; my $str="himanshu.txt^@"; if($str =~ /(\w+)/) { $str = "$1.$2"; } print "$str\n" __END__ Use of uninitialized value in concatenation (.) or string at - line 6. himanshu.
#!/usr/bin/perl -- use strict; use warnings; use re 'debug'; my $str="himanshu.txt^@"; if($str =~ /(\w+)/) { $str = "$1.$2"; } print "$str\n" __END__ Compiling REx `(\w+)' size 7 Got 60 bytes for offset annotations. first at 4 1: OPEN1(3) 3: PLUS(5) 4: ALNUM(0) 5: CLOSE1(7) 7: END(0) stclass "ALNUM" plus minlen 1 Offsets: [7] 1[1] 0[0] 4[1] 2[2] 5[1] 0[0] 6[0] Matching REx "(\w+)" against "himanshu.txt^@" Matching stclass "ALNUM" against "himanshu.txt^@" Setting an EVAL scope, savestack=5 0 <> <himanshu.txt> | 1: OPEN1 0 <> <himanshu.txt> | 3: PLUS ALNUM can match 8 times out of 2147483647.. +. Setting an EVAL scope, savestack=5 8 <manshu> <.txt^@> | 5: CLOSE1 8 <manshu> <.txt^@> | 7: END Match successful! Use of uninitialized value in concatenation (.) or string at test.pl l +ine 7. himanshu. Freeing REx: `"(\\w+)"'
In reply to Re: pattern matching
by Anonymous Monk
in thread pattern matching
by himanshu.padmanabhi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |