StuPeas
08-18-2006, 02:04 PM
This one should be simple (I hope).
$letters = "aaaabbbb";
$letters =~m/\w*(.)\1\w*/;
print "the letter $1 was found consecutively";
In the above, why isnt $1 set to "a" instead of "b".
The way i see it, the first match (\w*) would match the first "a".
The second match ((.)) would match the second "a".
The third match (\1) will only now match if it is the same as (.), which it is, i.e "a".
And the last match (\w*) would be taken care of by the remainder.
So why does perl skip the "a"'s and instead match on the "b"',.
TIA
$letters = "aaaabbbb";
$letters =~m/\w*(.)\1\w*/;
print "the letter $1 was found consecutively";
In the above, why isnt $1 set to "a" instead of "b".
The way i see it, the first match (\w*) would match the first "a".
The second match ((.)) would match the second "a".
The third match (\1) will only now match if it is the same as (.), which it is, i.e "a".
And the last match (\w*) would be taken care of by the remainder.
So why does perl skip the "a"'s and instead match on the "b"',.
TIA