在JavaScript中访问Perl数组
我在其他perl模块生成的perl中有一个未知大小的数组。 现在,我想要找到传递给jquery函数的值是否存在于perl数组中。
有没有办法我可以通过元素比较输入值与perl数组中的每个值进行元素的比较?
我环顾四周,看起来我可以通过提供索引来访问jquery中的perl数组,但我们不知道数组的大小。 所以我不知道什么时候停下来。
我的梅森代码看起来类似于:
my @testArray = [call to some other perl module to get the values] function checkIfValExistsInTestArray(val) { // Code to test if "val" exists in "@testArray". Returns boolean true/false. }
要检查是否存在,您需要哈希。 传输数据的一种简单方法是使用JSON
对其进行编码。
% use JSON qw( );
例如,如果get_values()
返回apple
和orange
,那么你就得到了
我不认识梅森,所以可能有错误,但你明白了。