in reply to Re^12: Converting hash into js object properties
in thread Converting hash into js object properties

nysus:

That looks like a good start. I find myself writing variations of that from time to time.

For checking when you need to quote values, I suggest looking at Scalar::Utils--it provides the function looks_like_number() which I use all the time to do things like that:

$val = wrap($val, '"') if defined $val and length($val) and ! looks_li +ke_number($val);

You may also want to handle the array case, as well as protect yourself in the event that your keys aren't legal keys in javascript (i.e., have blanks, punctuation, etc.).

...roboticus

When your only tool is a hammer, all problems look like your thumb.