in reply to Regular expression match and substitution
Change
$ref =~ s/(\$\S)/\$sym->{'$1'}/g
to
$ref =~ s/(\$\S+)/\$sym->{'$1'}/g
Of course, that won't work too well if the person uses
$x+$y=7
instead of
$x + $y = 7
so you might want to use
$ref =~ s/(\$\w+)/\$sym->{'$1'}/g
I presume you will later eval this string? I don't think that's a very good idea. I would indeed recommend using a parser.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular expression match and substitution
by pip9ball (Acolyte) on Nov 09, 2004 at 18:56 UTC | |
by ww (Archbishop) on Nov 09, 2004 at 19:09 UTC | |
by ikegami (Patriarch) on Nov 09, 2004 at 19:20 UTC | |
by pip9ball (Acolyte) on Nov 09, 2004 at 19:42 UTC | |
by ikegami (Patriarch) on Nov 09, 2004 at 21:35 UTC |