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
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