in reply to Using regex in Map function
You need to remember that the result of map is the list of the final value of each pass through its block. The value of s/// is a boolean indicating whether a replacement was made. You want the final value of the map block to be $_. Like so:
@new = map { s/$_/$_,hi/; $_ } <TEST>;
However, your substitution is less than ideal. In particular, you'll have problems if $_ contains any regex-special characters. If you're simply appending, you could do this:
or, even@new = map { s/$/,hi/; $_ } <TEST>;
@new = map { $_ . ',hi' } <TEST>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using regex in Map function
by grinder (Bishop) on May 02, 2007 at 22:00 UTC | |
|
Re^2: Using regex in Map function
by jettero (Monsignor) on May 02, 2007 at 21:14 UTC | |
|
Re^2: Using regex in Map function
by pKai (Priest) on May 02, 2007 at 21:21 UTC | |
|
Re^2: Using regex in Map function
by strat (Canon) on May 03, 2007 at 09:57 UTC |