...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?
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
|