in reply to two regexes in one function call
It looks like second regex result is overwriting also the first result.
Indeed.
$data = do { local $/ = undef; <DATA> }; print \$_, "\n" for scalar($data =~ s/\n/\n/g), scalar($data =~ s/(\w+)/\1/g); __DATA__ Line1 Word Something Line2 Other Word
SCALAR(0x239224) \ Same var! SCALAR(0x239224) /
In ActivePerl 5.10.0 build 1004, s/// appears to place the return value in a global variable, and it appear to place that global variable (not a copy) on the stack.
By the way, it's wrong to use \1 in the replacement expression. Use $1.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: two regexes in one function call
by BrowserUk (Patriarch) on Jul 28, 2009 at 16:43 UTC | |
by ikegami (Patriarch) on Jul 28, 2009 at 16:56 UTC |