in reply to global regex

ok, everybody hammered the nail on its head, here is a bullet of mercy. You're using a loop, but you've got to realize that when this loop iterates over and over it comes on the pattern and the code you wrote over and again:
/(\w+)/g; print "$1";
so, you use only one backreference ($1), that gets populated -from the start-everytime the loop iterates, so what you are doing wrong is assuming that for every file there gotta be separate variables to fill up but the fact is the while(<DATA>){} fetches a new DATA item everytime it goes through and replace it in the $1...hope you got the idea....best of luck
Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind

Replies are listed 'Best First'.
Re^2: global regex
by biohisham (Priest) on Jul 08, 2009 at 16:11 UTC
    I thought I will extend my previous reply with this code to show you that $1 is filled up over and over with new DATA...
    use strict; use warnings; my $match=0; while(<DATA>){ while(my $text = /Name: *(\w+)/g){ ++$match; print "Match no. $match is $1\n"; } } __DATA__ Name: Alpha Name: Beta Name: Gamma Name: Epsilon Name: Delta
    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind