package Foo; use strict; my $config = _parse_file(); sub new { my $proto = shift(); my $status = shift() || 'normal'; my $package = ref($proto) || $proto; my $self = { status => $status }; bless($self, $package); return $self; } sub change_config { my $self = shift(); return unless $self->{status} ne 'admin'; $config = _parse_file(); } sub show_config { foreach (keys(%{$config})) { print "KEY: $_\tVALUE: $$config{$_}\n"; } } sub _parse_file { my $filename = 'test.cfg'; my %temp; open(CONFIG, "<$filename") or die "can not open!\n"; while () { chomp($_); my ($key, $value) = $_ =~ m/^(\w+)=(.*)$/; $value ||= ''; $temp{$key} = $value if ($key); } close(CONFIG); return \%temp; } 1;