René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

grep [Perl]

use warnings;
use strict;

my $searched_letter = 'o';
my @items = qw(one two three four five six seven);

my @found_items = grep /$searched_letter/, @items;

print join "\n", @found_items;
one
two
four
use warnings;
use strict;

my $searched_word = 'bar';

my @words = qw(foo bar baz);

if (grep /\b$searched_word\b/, @words) {
  print "yes\n";
}
else {
  print "no\n";
}

@words = qw(morefooetc morebaretc morebazetc);

if (grep /\b$searched_word\b/, @words) {
  print "yes\n";
}
else {
  print "no\n";
}
yes
no