develooper Front page | perl.beginners | Postings from September 2009

match pattern

Thread Next
From:
raphael.japh
Date:
September 18, 2009 09:40
Subject:
match pattern
Message ID:
a81c2f2d0909180940h4eb5f7d4j83c1f5694d1b5df7@mail.gmail.com
Hi

How do I pick out matching words if there are more than one on the same
line?


Example

INFILE.TXT

www.site01.com www.site02.com www.site03.com
www.site04.com

------

while (<>) {
    if ( m!(www.\S+.com)!s ) {
#       print "$1\n";
#       print "$&\n";
        print;
    };
}
------

I want to get all the 'match' in the INFILE.TXT on separate lines to
OUTFILE.TXT

www.site01.com
www.site02.com
www.site03.com
www.site04.com

But all I get is

www.site01.com
www.site04.com

If I try $1 or $& I only get two instances of 'match'  from the first in the
line.
Any help is appreciated

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About