(Just to get this out of the way first: I agree with CountZero and the previous Anonymous answerer that you should consider another way to deal with config files.)

Back up a bit. Understand that your do(), if successful, puts the last expression in $config_file into the variable $return, but you're throwing that value away in your code!

This is how I'd go about it:

First, format your config file as a single hash reference expression like this:

{ default => { 'BM_shutts_south_00' => 1, 'BM_shutt_north_00' => 1, }, };

I just used your defaults above, so update as necessary.

To read the config file:

# define %Log_rooms out here, where it will remain in scope: my %Log_rooms = ( default => { 'BM_shutts_south_00' => 1, 'BM_shutt_north_00' => 1 } ); my $return = do $config_file; if ($return && UNIVERSAL::isa($return, 'HASH')) { # we got a hash reference back, so override the defaults: %Log_rooms = %$return; } else { # do whatever you need to do to recover warn "Using default values.\n"; }

In reply to Re^3: Cannot read hash variable from file as global... by drench
in thread Cannot read hash variable from file as global... by Anonymous Monk

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.