Eval fails in certain situations (eval "{'...")
On Sun, 20 Jul 1997 16:02:05 MDT, Dave Carrigan wrote:
>Eval will fail in the following situation:
>
>- eval'ing a string
>- the string represents an anonymous hash
>- the first key of the anon hash is single quoted, and contains an
> embedded single quote escaped with a backslash
>- using the form `` $ref = eval $string ''
>
>The MLDBM module uses this form of eval all the time, so the above
>situation actually has the potential to occur quite often.
>$string2 = "{'a\\'' => 'foo', 'b' => 'bar', 'c' => 'bat'}";
That is one of the cases where the note in perlref (about
disambiguating braces not preceded by anything else) applies.
However, in this particular case, the code that recognizes if
a literal string is the first thing inside the curlies is not
doing a thorough job of it. The attached patch should cure
it.
Note that you'll still need to write C<eval "{ $a => 'foo' }">
as C<eval "+{ $a => 'foo' }"> if you want it to evaluate as a
hashref. Perl only auto-disambiguates if the first thing in
the curlies is a literal string followed by a comma or =>.
I'll change MLDBM to conform, for the next release.
p5p-msgid:
199707211753.NAA14940@aatma.engin.umich.edu