in reply to Re^3: Unnecessary use of capturing in regex?
in thread Unnecessary use of capturing in regex?

Thank you for your explainationS to me,I know the "()" has memory function, also I know that the function of ".", I enconter
#!\usr\bin\perl -w for($_="head";s/(.)//;){ print"now head is $_.\n"; }
in the book learning perl, I am confused why not just "." So I ask this question.

Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re^5: Unnecessary use of capturing in regex?
by gothic_mallard (Pilgrim) on Nov 03, 2004 at 14:56 UTC

    As previously mentioned, in this particular case there isn't any reason to use "(.)" over purely "."

    If you were going to require the value you replaced here afterwards for another purpose then it would make sense. Otherwise "(.)" has no advantages that I'm aware of.

    --- Jay

    All code is untested unless otherwise stated.
    All opinions expressed are my own and are intended as guidance, not gospel; please treat what I say as such and as Abigail said Think for yourself.
    If in doubt ask.