waldner has asked for the wisdom of the Perl Monks concerning the following question:
Up to this, everything as expected. But now:$ perl -We '$_="I have 10 dollars.\n"; s/(10)/$1/; print;' I have 10 dollars. $ perl -We '$_="I have 10 dollars.\n"; s/(10)/$1+1/; print;' I have 10+1 dollars. $ perl -We '$_="I have 10 dollars.\n"; s/(10)/$1+1/e; print;' I have 11 dollars.
What I don't understand is why, in the second case, the first and second outputs are the same, and thus I need two /ee to have the expression evaluated. After all, $1 is already "10+4", so a single /e should be enough to evaluate it.$ perl -We '$_="I have 10+4 dollars.\n"; s/(10\+4)/$1/; print;' I have 10+4 dollars. $ perl -We '$_="I have 10+4 dollars.\n"; s/(10\+4)/$1/e; print;' I have 10+4 dollars. $ perl -We '$_="I have 10+4 dollars.\n"; s/(10\+4)/$1/ee; print;' I have 14 dollars.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /e in regexes
by ikegami (Patriarch) on Jun 22, 2008 at 16:33 UTC | |
by waldner (Beadle) on Jun 22, 2008 at 16:44 UTC | |
by moritz (Cardinal) on Jun 22, 2008 at 16:48 UTC | |
by ikegami (Patriarch) on Jun 22, 2008 at 16:59 UTC | |
by waldner (Beadle) on Jun 22, 2008 at 17:02 UTC | |
|
Re: /e in regexes
by shmem (Chancellor) on Jun 22, 2008 at 16:44 UTC | |
|
Re: /e in regexes
by Fletch (Bishop) on Jun 22, 2008 at 16:37 UTC | |
|
Re: /e in regexes
by pc88mxer (Vicar) on Jun 22, 2008 at 17:34 UTC |