Hi,

I'm having problems by reading hash variables from "config" files ...

I have this in test.conf file :
%Log_rooms = ( "gallery" => { 'BM_shutts_south_00' => 1, 'BM_shutt_no +rth_00' => 1 } );

then I have Cybro_Items.pm:
my $config_file ="/etc/test.conf"; my %Log_rooms; t if (-e $config_file) { print "Reading Configuration from $config_file \n\n"; my $return = do $config_file ; warn "couldn't parse $config_file: $@" if $@; warn "couldn't do $config_file: $!" unless defined $return; warn "couldn't run $config_file" unless $return; } else { print "Using Default Configuration \n\n"; t %Log_rooms = ( "default" => { 'BM_shutts_south_00' => 1, 'BM_ +shutt_north_00' => 1 }, ); ... package Cybro_Item; ... sub get_extra_rooms_for_log { my($self,$var_name) = @_; my %match=undef; while(($room, $room_hash) = each(%Log_rooms)) { ...

if config file doesn't exist, everything works ok with predefined default variable content. If config file exists, then %Log_rooms is empty...

What do I have to put into test.conf file or how to read it in right way, so I could get variable content either from default settings or configuration file... I guess I also have some mistakes on how to deal with variables in such situation. I'd like to have %Log_rooms as global variable, visible from everywhere - let me stress that Cybro_Item package is used in another main test.pl program as :
use Cybro_Items;
I'd kindly ask for some help,

thanks in advance,

regards,

Bulek.

In reply to 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.