* anand kumar <[EMAIL PROTECTED]> [2005-12-11T22:38:00] > I am new to perl .i have a doubt in analysing the following regex. > (my $book = $ref_string) =~ s/\s*(\d+(?::\d+(?:-\d+(?::\d+)?)?)?)\Z//; > > here i want to know the meaning of '?:'
Normally, something enclosed in parentheses would be "captured" for later use. For example: (my $altered_string = $string) =~ s/\A123(\d+)\z/321$1/; This would change "1238302938" to "3218302938" by capturing the digits after 123 into $1, which is later interpolated in the right-hand side of the s/// expression. ?: inside the parentheses indicates that you don't want to capture. (my $altered_string = $string) =~ s/\A123(?:\d+)\z/321something/; Here, since we don't care about the digits after 123, we can throw them away, so we don't need to capture them. For this reason, we use ?: to say "group these together, but don't capture them. There are many uses for this. In the example you provided, it is probably being done for the small optimization it provides. -- rjbs
pgptyegtLuESK.pgp
Description: PGP signature