简体   繁体   中英

How to deference a reference to a scalar in an array

I have following piece of code

$var1 = 10;

@arr = (1, \$var1, 3);

print "var1= $$arr[1] \n";

This is not printing value 10, is this syntax $$arr[1] correct? using additional variable i was able to print the value

$r = $var[1];

print "var1 = $$r\n";

If it's $NAME if you have the name, it's $BLOCK if you have a reference. So,

${ $arr[1] }

or (5.24+)

$arr[1]->$*

or (5.20+)

use experimental qw( postderef );

$arr[1]->$*

References:

尝试这个

print "var1 = ${ $var[1] }\n" ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM