in reply to How to grep exact string
This checks if any of @first_list_new is equal to $unique. Unlike grep, it will stop as soon as it finds a match.foreach my $unique (@second_list_new) { if ($unique ~~ @first_list_new)) { print "already there $unique\n\n"; } else { print "newly in this $unique\n\n"; } }
This ensures that it will match the literal content of $unqiue. Otherwise, some characters within $unique could be interpreted as special regex characters. This wouldn't be a problem with the sample data you have shown, but if you were searching for a value like "foo.bar", for example, it wouldn't do what you want without \Q...\E, because the . would match any character rather than a literal dot.if (grep (/^\Q$unique\E$/,@first_list_new))
my @first_list_new = map { s/\s*$//m; lc $_ } <FIRST_LIST>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to grep exact string
by tobyink (Canon) on Nov 15, 2012 at 09:06 UTC | |
by Kenosis (Priest) on Nov 15, 2012 at 22:14 UTC | |
by ColonelPanic (Friar) on Nov 15, 2012 at 09:34 UTC | |
by tobyink (Canon) on Nov 15, 2012 at 10:13 UTC |