Question

Is it possible to include JQuery in the here-doc section of perl. I tried but no success. Here is my code.

my $cgi = CGI->new();print header();print start_html("JQuery in perl");

print <<JS;
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script><!--
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
 });
});
//--></script>

<p>Click to hide</p>
<p>Click to hide</p>
<p>Click to hide</p>
</body>
JS
print end_html();

But when I write a javascript function, it works fine

my $cgi = CGI->new();print header();print start_html("hello");
print <<JS;
<script><!--
function show() {alert("Hello");}
//--></script>
<input type="button" value="Check"  onclick="show()">
</body>
JS
print end_html();

Am I missing something obvious here ?Please suggest.

Was it helpful?

Solution

A here-doc works similar to a double-quoted string: variables are evaluated. As $( is actually a variable in Perl it will get replaced by the process' real group ID. Escape it with a backslash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top