Retrieving information from another package in Perl - Syntax -
i have package called pack1::i1 , package called pack2::i2. inside pack2 there sub called foo. syntax me retrieve sub pack2 if in pack1?
something this?:
package pack1 sub hello {    $self = shift;    $x = pack2::i2->foo; } thanks
you need use qualified name of subroutine. here example.
use strict; use warnings;  package pack1::i1;  sub hello {    $self = shift;    print pack2::i2::foo(), "\n"; # qualified name }  # sub found because in namespace pack1::i1 hello();  package pack2::i2;  sub foo {     return "foo pack2::i2::foo()"; } however, more common approach use module exporter. there con export functions namspace pack1::i1 namespace pack2::i2.
also please not the convention capitalise namespaces.
Comments
Post a Comment