in reply to Can't get the desired output..
This is not the spot for a full regex tutorial but it appears to me that you need to use a capture to do what you want:
if ($name =~ /(Cobray)/){ say "$1";}
The parentheses tell the regular expression engine to capture their content (if that content exists in the line (of 3, comma-separated names, in this case) to the special variable, $1.
Just a side note: I've written the code this way to stay close to your original... and to make the illustration fairly clear. But good practice calls for an intermediate step; assigning $1 to a named variable that won't be transient nor have the properties (esp. durability) of $1 that make it retain a prior match, if a new attempt fails.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't get the desired output..
by locked_user sundialsvc4 (Abbot) on May 02, 2012 at 15:19 UTC |