F
freesoft12
Hi,
I want to concatenate multiple regular expressions using '||' or '&&'
operations in a 'grep' call.
---------------------
For example:
my @orig_list = ('apple', 'orange', 'pineapple','banana','pear');
# I want to find 'apple' or 'banana' in the list
my @regex_str = "/apple/ || /banana/";
# negate the concatenated expresson so that
# the 'grep' call will return 'orange' , 'pear'
my @results = grep( ! $regex_str,@orig_list);
# print 'orange', 'pear'
foreach my $r (@results) {
print $r." ";
}
print "\n";
-------------------------------------
This program currently doesn't match anything. I get an empty
'@results' list.
Any suggestions?
Regards
John
I want to concatenate multiple regular expressions using '||' or '&&'
operations in a 'grep' call.
---------------------
For example:
my @orig_list = ('apple', 'orange', 'pineapple','banana','pear');
# I want to find 'apple' or 'banana' in the list
my @regex_str = "/apple/ || /banana/";
# negate the concatenated expresson so that
# the 'grep' call will return 'orange' , 'pear'
my @results = grep( ! $regex_str,@orig_list);
# print 'orange', 'pear'
foreach my $r (@results) {
print $r." ";
}
print "\n";
-------------------------------------
This program currently doesn't match anything. I get an empty
'@results' list.
Any suggestions?
Regards
John