Tuesday, 15 September 2015

perl - Why can't I access lexical variables through a typeglob? -



perl - Why can't I access lexical variables through a typeglob? -

i don't understand why illustration below fail (test 2). why cant access variable bb *bb glob?

use test::more tests => 4; $aa = 1; $bb = 2; # here! local $cc = 3; our $dd = 4; is(${*aa}, 1, "$ \*aa should 1"); is(${*bb}, 2, "$ \*bb (my) should 2"); is(${*cc}, 3, "$ \*cc (local) should 3"); is(${*dd}, 4, "$ \*dd (our) should 4");

the output is

1..4 ok 1 - *aa should 1 # failed test '*bb (my) should 2' # @ untitled line 10. # got: undef # expected: '2' # looks failed 1 test of 4. not ok 2 - *bb (my) should 2 ok 3 - *cc (local) should 3 ok 4 - *dd (our) should 4

under perl 5.16.0

thanks

lexical variables (those created my) not part of symbol table, cannot reached globs. see of symbol tables , globs.

perl

No comments:

Post a Comment