in reply to Re^2: perl regex
in thread perl regex
so /(need)/ would match the word need.
... and return the matched word 'need'; but yes.
However, what is the purpose of capturing the matched word when you already know what it is?
Ie. If your intent is to do:
my( $foundWord ) = $string =~ /(need)/;
That is equivalent to doing:
my $foundWord = $string =~ /need/ ? 'need ' : undef;
The point being that capturing is expensive and the need to capture a known constant string is strongly indicative of flawed logic.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: perl regex
by BrowserUk (Patriarch) on Nov 13, 2016 at 23:07 UTC |