You can actually give explicit package name to satisfy strict (like it says). Like this:
%main::GLOBAL = ( dir1 = "/path/to/directory", dir2 = "/path/to/another", );
and then in read_config_files:
sub read_config_files { $main::GLOBAL{newstuff} = "a string that was added"; # etc }
That's assuming that %GLOBAL lives in the main package, which I suppose it does. For refactoring, perhaps it would be clearer to give it its own package:
# this is file global.pl use strict; use warnings; package GlobalStuff; %GlobalStuff::GLOBAL = ( dir1 = "/path/to/directory", dir2 = "/path/to/another", ); # or, alternatively (same thing) our %GLOBAL = ( dir1 = "/path/to/directory", dir2 = "/path/to/another", );
and
# this is file config.pl use strict; use warnings; require 'global.pl'; read_GLOBAL(); print_GLOBAL(); # for example sub read_GLOBAL { $GlobalStuff::GLOBAL{new} = 'a string'; } sub print_GLOBAL { while ( my ($k, $val) = each %GlobalStuff::GLOBAL ) { print "$k => $val\n"; } }
Then I would rename 'global.pl' to 'GlobalStuff.pm', and change all calls to require accordingly:
require GlobalStuff;
require appends .pm to a bareword and searches this file in @INC; see require for details.

In reply to Re: Modifying/Accessing hash in separate script by Anonymous Monk
in thread Modifying/Accessing hash in separate script by mdskrzypczyk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.