There's probably a really simple answer to this one. 
I'm trying to find multiple matches to a regex within
a file, replace them, and save in another file...

#!/usr/bin/perl -w
use warnings;
use strict;
open(INFILE, "<1.ls") or die("Couldn't open input
file.\n");
open(OUTFILE, ">3.ls") or die("Couldn't open output
file.\n");
# Should match H, E, and R
while(<INFILE>)
{
    my @matches = m/([A-Z])[A-Z]{2,}/;
    print "@matches\n";
}

The input file contains: 
HELLo

WoRLD

The output I'm getting is H and R, never E.  It
appears as though either I'm only getting the first
match it finds per line (I think adding g should fix
this but it doesn't in this case) or since the first
match is 'HEL', that leaves 'Lo' for the second match,
which fails.  So basically, I need the second match to
be 'ELL'.  I always thought regexes walked through the
string char by char.  So what am I doing wrong here? 
Thanks.  ~Frank


                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to