> -----Original Message----- > From: raphael() [mailto:raphael.j...@gmail.com] > Sent: Friday, September 18, 2009 10:40 > To: Perl BEGIN > Subject: match pattern > > 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; > }; > } > ------ Here is one way: while (<DATA>) { # used __DATA__ for testing while ( m!(www.\S+.com)!ig ) { # print "$1\n"; # print "$&\n"; print $1 . "\n"; }; } You only need to add the open for the output.
The script looked like: #!/usr/bin/perl use strict; use warnings; while (<DATA>) { while ( m!(www.\S+.com)!ig ) { # print "$1\n"; # print "$&\n"; print $1 . "\n"; }; } __DATA__ www.site01.com www.site02.com www.site03.com www.site04.com If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us > > 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 > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/