in reply to Re: Re: Re: How can grep search based on text or pattern based on user input?
in thread How can grep search based on text or pattern based on user input?
Adjust the sanity checking on $mod however you like. BTW, Perl allows (?x) as well as (?ism), but I figured you wouldn't need that here.@stuff = ('This is Some text.','This is More text.'); $stext = '/some/i'; ($null, $text, $mod) = split(/\//, $stext); if ($mod and $mod !~ /[^ism]/) { # a little sanity checking on the mo +difers $mod = "(?$mod)"; } else { $mod = ''; } foreach (grep /$mod$text/, @stuff) { print $_, "\n"; }
|
|---|