I have an array of unknown size in perl generated by some other perl module. Now, precisely I want to find if a value passed to a jquery function exists in the perl array or not
To check for existence, you'd want a hash. A simple way of transmitting the data would be to encode it using JSON.
% use JSON qw( );
<script type="text/javascript">
var testArray = <% JSON->new()->encode({ map { $_ => 1 } get_values() }) %>;
function checkIfValExistsInTestArray(val) {
return testArray[val];
}
</script>
For example, if get_values()
returned apple
and orange
, you'd get
<script type="text/javascript">
var testArray = {"apple":1,"orange":1};
function checkIfValExistsInTestArray(val) {
return testArray[val];
}
</script>
I don't know Mason, so there could be errors, but you get the idea.