Reading another packages symbol table in Perl

Posted by justintime on Stack Overflow See other posts from Stack Overflow or by justintime
Published on 2010-04-17T19:55:10Z Indexed on 2010/04/17 20:23 UTC
Read the original article Hit count: 145

Filed under:

I am trying to read a global symbol from another package. I have the package name as a string. I am using qualify_to_ref from Symbol module

    my $ref  = qualify_to_ref ( 'myarray', 'Mypackage' ) ;
    my @array =  @$ref ;

gives me Not an ARRAY reference at ...... I presume I am getting the format of the dereference wrong.

Here is a complete example program.

    use strict;
    use Symbol ;

    package Mypackage ;
    our @myarray = qw/a b/ ;

    package main ;

    my $ref  = qualify_to_ref ( 'myarray', 'Mypackage' ) ;
    my @array =  @$ref ;

© Stack Overflow or respective owner

Related posts about perl