in reply to Re^2: Unnecessary use of capturing in regex?
in thread Unnecessary use of capturing in regex?
...tell me why the two can come to the same result...
#!\usr\bin\perl -w for($_="head";s/(.)//;){ print"now head is $_.\n"; } #!\usr\bin\perl -w for($_="head";s/.//;){ print"now head is $_.\n"; }
The only difference between your (updated) two samples, is that in the first you have capturing brackets. These will cause the matched character to be copied into $1. But then you do nothing with $1, so otherwise both samples are the same:
Match a (the first) character in $_, and then delete it; print out the contents of $_; repeat until no match occurs, which will be when $_ is empty.
What difference were you expecting?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Unnecessary use of capturing in regex?
by biofeng918 (Acolyte) on Nov 03, 2004 at 14:48 UTC | |
by gothic_mallard (Pilgrim) on Nov 03, 2004 at 14:56 UTC |