importing a hash from package

J

Jeff Thies

I'm sure this is easy, but I'm not finding it...

I have a package with a heash in it:

package VARIABLES;

my %HASH;
$HASH{a}='a';

$some_scalar='some_scalar'

....

I want to refer to that hash elsewhere.

I know I can do this:

my $local_some_scalar=VARIABLE::$some_scalar;

But, how do I get at HASH? Do I have to write a reference to it in
package VARIABLES?

Cheers,
Jeff
 
S

Steve Grazzini

Jeff Thies said:
package VARIABLES;

my %HASH;
$HASH{a}='a';

$some_scalar='some_scalar'

...

I want to refer to that hash elsewhere.

I know I can do this:

my $local_some_scalar=VARIABLE::$some_scalar;
^^^^^^^^^^^^^^^^^^^^^^

That's not quite right.
But, how do I get at HASH? Do I have to write a reference to it
in package VARIABLES?

The difference is between lexical (my) variables, which you can't
use outside the scope where they were declared, and package variables,
which are global.

You can use our() to declare package variables.

our %HASH; # %VARIABLES::HASH

Is that what you were after?
 
J

Jeff Thies

Steve said:
oops!


That's not quite right.


The difference is between lexical (my) variables, which you can't
use outside the scope where they were declared, and package variables,
which are global.

You can use our() to declare package variables.

our %HASH; # %VARIABLES::HASH

Is that what you were after?

Yes, thanks!

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top