raphael() wrote:
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


You use the /g flag to get more than one match in a loop:

#!/usr/bin/perl

use strict;
use warnings;


while( <DATA> ){
  while( m{ \b ( www \. \S+ \. com ) \b }gmsx ){
    print "$1\n";
  }
}

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


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to