Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
# build regular expression from command line args my $re; foreach my $arg (0 .. $#ARGV){ if($arg == $#ARGV){ $re .= "/(\\x01.?$ARGV[$arg].?\\x01)/"; }else{ $re .= "/(\\x01.?$ARGV[$arg].?\\x01)/&&"; } } while (<STDIN>){ if($re){ print "$_\n"; } } print "equivalent grep: grep -P \"$re\"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating regular expressions dynamically from the command line
by kennethk (Abbot) on Dec 14, 2010 at 20:14 UTC | |
|
Re: creating regular expressions dynamically from the command line
by planetscape (Chancellor) on Dec 14, 2010 at 20:41 UTC | |
|
Re: creating regular expressions dynamically from the command line
by AnomalousMonk (Archbishop) on Dec 15, 2010 at 11:18 UTC |