CGI error Can't use an array as a reference

假装没事ソ 提交于 2021-01-28 06:50:26

问题


My configuration is Debian Stretch

I verify my Perl code with the command

line perl -wcT admin.cgi

I have an error in the code at this line:

print &select("$id-2",\@values,\@values,@{$FORMAT{$name}}->[1]),"<br /> \n";

The error is:

Can't use an array as a reference

I also tried with this web editor

It seems that the error is :

@{$FORMAT{$name}}->[1]

回答1:


As you say, the problem is here:

@{$FORMAT{$name}}->[1]

It appears that $FORMAT{$name} is expected to contain an array reference. And you want to get the second element from the referenced array. There are (at least!) two ways to do this.

You can dereference the array reference to get an array and then use standard array indexing brackets:

@{$FORMAT{$name}}[1]

Or you can use the deferencing arrow along with array indexing brackets:

$FORMAT{$name}->[1]

What you can't do (as you've found) is to use both syntaxes simultaneously :-)

Update: As Borodin points out in a comment, my first solution is incorrect. When accessing a single element from an array, you should change the @ to a $. So it should actually be:

${$FORMAT{$name}}[1]

And in my second solution, the arrow is actually optional (dereferencing arrows between two sets of brackets always are), so you can write:

$FORMAT{$name}[1]



回答2:


my cgi called webadmin.cgi now is on ActivePerl with Xampp on my pc windows 7.

this one works (run perfectly) in local test with the same error:

print &select("$id-2",\@values,\@values,@{$FORMAT{$name}}->[1]),"<br /> \n";

and if install the same files on OS debian stretch (my dedicated server) finally:

if i test with the same error of syntax it doesn't work (error 500)

if i replace with twice solution, the program on line run but eject me.

thanks for your patience,

Ornot



来源:https://stackoverflow.com/questions/51950005/cgi-error-cant-use-an-array-as-a-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!