Get a variable inside package
how can i get a variable inside a package
example:
{ package example;
my $baz = "sometext";
sub new{
my $self = shift;
bless \$self;
}
}
my $foo = example->new;
how can I get the value of $baz i tried
print $foo->{vv};
print $foo::vv
and no luck
thanks
terabyte
Junior Poster in Training
68 posts since Oct 2010
Reputation Points: 10
Solved Threads: 4
You have declared $baz with the my function which limits the scope of $baz to the block in which it is declared thus making it impossible to obtain its value from outside that block. A my declares the listed variables to be local (lexically) to the enclosing block ...
In the following script I changed the my to our and deleted the statements not necessary for defining $baz and referring to its value from outside the package:
#!/usr/bin/perl
use strict;
use warnings;
{ package example;
our $baz = "sometext";
}
print $example::baz;
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159