On Wednesday 27 Jan 2010 18:21:01 Jim Gibson wrote: > At 6:44 PM +0530 1/27/10, V U Maheswara rao k wrote: > >Thanks Jhon, > > > >my search string may be more than 100 words like ("warnings", "errors", > >"Caution","Debug","notice","info"..etc). so that I want to get it from > >array and search it in each line > >I want to search a list in a line of file. > > Alternation is still the way to go. If you have yours words to search > for in an array (e.g., @words), form your regular expression this way: > > my $re = join('|',@words); >
Better yet, use perldoc -f quotemeta: ---- my $re_str = join('|', map { quoteameta($_) } @words); my $re = qr{$re_str}; ---- Regards, Shlomi Fish > Then use it this way: > > while(<$fh>) { > if( /$re/o ) { > print; > } > } -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Why I Love Perl - http://shlom.in/joy-of-perl Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/