Mailing List Archive

possible html replacement bug
Hi,

I have encountered what may be a bug of sorts in Embperl -- or perhaps
there's a way to fine-tune Embperl's behavior that I don't understand. I
am attempting to dynamically write javascript as follows:

[-
$query = $param[0];
$col_name = $param[1];
$i = 0;
-]
[$ if ($query) $]
[- $result = $query->get_next_hashref(); -]
[$ while ($result) $]
dest.options[[+ $i +]].text = "[+ $result->{$col_name} +]"
dest.options[[+ $i +]].value = "[+ $result->{$col_name} +]"
[-
$i++;
$result = $query->get_next_hashref();
-]
[$ endwhile $]
[$ else $]
dest.options[0].text = "No values found!"
[$ endif $]


`$query' is an object that basically encapsulates the result of a database
query; the result of $query->get_next_hashref() is the same as DBI's
fetchrow_hashref() function. If the query had just one hashref, and if
`$col_name' were "foo", and if the value of the `foo' key was "bar", we
would expect to see:

dest.options[0].text = "bar"
dest.options[0].value = "bar"

But instead we see:

dest.options[+ $i +]].text = "bar"
dest.options[+ $i +]].value = "bar"

However, if the original code is changed to:

dest.options[ [+ $i +] ].text = "[+ $result->{$col_name} +]"
dest.options[ [+ $i +] ].value = "[+ $result->{$col_name} +]"

...then we get:

dest.options[ 0 ].text = "bar"
dest.options[ 0 ].value = "bar"

Obviously, the workaround is to insert a space between any literal
open-square-bracket and the beginning of an Embperl string, however, this
seems like a bug.


steve
Re: possible html replacement bug [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 4:15 PM -0400 5/4/00, Steven D. Arnold wrote:
> dest.options[+ $i +]].text = "bar"
> dest.options[+ $i +]].value = "bar"

[.[. is the escape mechanism that embperl uses to escape a [, so it's
seeing "[[+ $i +]]" and assumin you really want to turn off special
processing of the "[+". Your work around works, as would:
dest.options[+"[$i]"+]
although that disrupts the logic of the language, which is poor.
Your cleanest solution is to excape the first [
dest.options[[[+ $i +]]
should do what you want
- --

Kee Hinckley - Somewhere Consulting Group - Cyberspace Architects(rm)

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBORHlWyZsPfdw+r2CEQLi0gCaA/Kqiki/+wrzapPYgWrS0cmlFYkAoOTj
HSoHbrONorMuNt3tWSiWdZtp
=/ypP
-----END PGP SIGNATURE-----