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

OK, so adding double quotes to the jQuery directly didn't break anything, the validator script still works with them. So I guess I'm good to go. Thanks!

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^8: Converting hash into js object properties

Replies are listed 'Best First'.
Re^9: Converting hash into js object properties
by haukex (Archbishop) on Nov 21, 2017 at 20:51 UTC
    adding double quotes to the jQuery directly didn't break anything

    jQuery is "just" a library, in that way it is similar to, for example, Moo: it just makes good/clever use of existing language syntax to provide an interface that makes it look like it's adding new syntax to the language (e.g. jQuery's $(...), Moo's has), but it is in fact working within the confines of the language (other modules can be added to provide sugar). The same way one can write regular Perl subs into Moo classes and use everything that Perl has to offer, one can use all of vanilla JavaScript when working with jQuery.

      Thanks.

      I have run into a bit of a roadblock. If a value is set to some jQuery code (let's say to get the value of a text field), it surrounds the jQuery code with quotes which does break things. Can you think of any good ways around this problem?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        nysus:

        OK, I was going on under the working assumption that you were creating JSON stuff that would be used that your JavaScript stuff would fetch from the server and use. It seems like you're actually generating JavaScript in your perl code to send off to the browser and execute. That's fine, of course, but it certainly complicates things a bit. Now you can't easily use JSON to build your data structures and handle the quoting for you because you've also got some plain JavaScript that you don't want to mangle.

        I've not worked in that space yet, so you may want to browse CPAN for other modules that might be useful. A perfunctory look gave up JavaScript::Code and JavaScript::Writer, perhaps one of those might be more in line with what you need.

        ...roboticus

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