Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:19:03+00:00 2026-05-15T09:19:03+00:00

for Ex : package test1 ; my %hash = ( a=> 10 , b

  • 0
for Ex : 
package test1 ; 

my %hash = ( a=> 10 , b => 30 ) ;

1;

in Script : 

use test1 ;

print %hash ;  # How to  make this avilable in script without sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:19:04+00:00Added an answer on May 15, 2026 at 9:19 am

    Good programming practice prescribes that you do not allow foreign code to mess with a module’s data directly, instead they must go through an intermediary, for example an accessor routine.

    TIMTOWTDI, with and without exporting. The Moose example appears quite long, but this one also allows setting data as opposed to just reading it from Test1, where the other three examples would need quite some additional code to handle this case.


    unsugared

    Module

    package Test1;
    {
        my %hash = (a => 10, b => 30);
        sub member_data { return %hash; }
    }
    1;
    

    Program

    use Test1 qw();
    Test1::member_data; # returns (a => 10, b => 30)
    

    Moose

    Module

    package Test1;
    use Moose;
    has 'member_data' => (is => 'rw', isa => 'HashRef', default => sub { return {a => 10, b => 30}; });
    1;
    

    Program

    use Test1 qw();
    Test1->new->member_data; # returns {a => 10, b => 30}
    # can also set/write data!  ->member_data(\%something_new)
    

    Sub::Exporter

    Module

    package Test1;
    use Sub::Exporter -setup => { exports => [ qw(member_data) ] };
    
    {
        my %hash = (a => 10, b => 30);
        sub member_data { return %hash; }
    }
    1;
    

    Program

    use Test1 qw(member_data);
    member_data; # returns (a => 10, b => 30)
    

    Exporter

    Module

    package Test1;
    use parent 'Exporter';
    
    our @EXPORT_OK = qw(member_data);
    
    {
        my %hash = (a => 10, b => 30);
        sub member_data { return %hash; }
    }
    1;
    

    Program

    use Test1 qw(member_data);
    member_data; # returns (a => 10, b => 30)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use CHDB (hash table caching) for PHP (http://pecl.php.net/package/chdb). I end up
Consider the following code: package Test1; use Moose; has 'something' => ( is =>
This is more like a package/import test. We'll start with my base folder at
This is my FragmentListArraySupport.java package com.test.methods; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.ListFragment; import android.util.Log;
I am getting: Can't call method test without a package or object reference at
I trying spring 3 mvc this package is org.spring.test and code is @Controller @RequestMapping(/welcome)
How do you completely delete a package in Perl? This means not only the
I am trying to convert a test password (testing4) into a phpbb3 hash. This
How do I compile and run the following programs: Test1.java: package A; public class
in the java test I have : package Tester.GUI.api public class Test1{-----} in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.