Note that the answers above rely on the array being comprised of single words (which may well be the case), However, if the elements being searched contain multi-word phrases or (for example) sentences (which is not specified in the OP), the results may not be as illustrated.
#! /usr/bin/perl use strict; use warnings; my @other_stuff = ("run", "running", "runs", "runt", "I run a mile per + day.", "Run, rabbit, run!", "One mile per day is easily runnable"); for my $element(@other_stuff) { print $element ."\n"; } print "-" x20 . "\n"; my @stuff = grep /\brun\b/x, @other_stuff; for (@stuff) { print $_ . "\n"; }
produces...
ww@GIG:~/pl_test$ perl greprun.pl run running runs runt I run a mile per day. Run, rabbit, run! One mile per day is easily runnable -------------------- run I run a mile per day. Run, rabbit, run! ww@GIG:~/pl_test$
Precise specification of a problem-area makes it easier for Perl Monks to provide proper answers (and standard spelling is a "good thing," too).
In reply to Re: grep - search limited to complete word only
by ww
in thread grep - serach limited to complete word only
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |