S
Sebastian Marants
Hello,
i have a module and my program that uses it.
i want to use the hash which is only declared
in my module within the main program.
I want the output to be
one
two
two
one
but it prints nothing
anyone can help me out and teach me the
scope of variables when using modules?
in other words: how can i make %MYCOOLHASH
available in test.pl without passing it by reference
or value.
thanks in advance
Sebastian
--- test.pl ------------------
use mycoolmodule;
print "$MYCOOLHASH{'test1'}\n";
print "$MYCOOLHASH{'test2'}\n";
&changeValues();
print "$MYCOOLHASH{'test1'}\n";
print "$MYCOOLHASH{'test2'}\n";
exit;
----------------------------------------
--- mycoolmodule.pm ------------------
my %MYCOOLHASH;
$MYCOOLHASH{'test1'} = "one";
$MYCOOLHASH{'test2'} = "two";
sub changeValues
{
$MYCOOLHASH{'test1'} = "two";
$MYCOOLHASH('test2'} = "one";
}
1;
exit;
----------------------------------------
i have a module and my program that uses it.
i want to use the hash which is only declared
in my module within the main program.
I want the output to be
one
two
two
one
but it prints nothing
anyone can help me out and teach me the
scope of variables when using modules?
in other words: how can i make %MYCOOLHASH
available in test.pl without passing it by reference
or value.
thanks in advance
Sebastian
--- test.pl ------------------
use mycoolmodule;
print "$MYCOOLHASH{'test1'}\n";
print "$MYCOOLHASH{'test2'}\n";
&changeValues();
print "$MYCOOLHASH{'test1'}\n";
print "$MYCOOLHASH{'test2'}\n";
exit;
----------------------------------------
--- mycoolmodule.pm ------------------
my %MYCOOLHASH;
$MYCOOLHASH{'test1'} = "one";
$MYCOOLHASH{'test2'} = "two";
sub changeValues
{
$MYCOOLHASH{'test1'} = "two";
$MYCOOLHASH('test2'} = "one";
}
1;
exit;
----------------------------------------