Hi list,

I'm trying to use eval () with a constants module and it works very
funny, can anyone explain this behavior to me. It seems to me as this is
a scope thing. If i remove the 'my' it works fine but i can't see why it
shouldn't work with my:

i have a module with constants (constants.pm):
##############################################################
package constants;
my %month_number = (
                    'Jan' => '01',
                    'Feb' => '02',
                    'Mar' => '03',
                    'Apr' => '04',
                    'May' => '05',
                    'Jun' => '06',
                    'Jul' => '07',
                    'Aug' => '08',
                    'Sep' => '09',
                    'Oct' => '10',
                    'Nov' => '11',
                    'Dec' => '12'
                    );

sub get_constant
{
    my $name = shift;
    my $ret = ();
     "$month_number{Dec}\n"; #    <------ ODD ROW
    eval '$ret = \\%month_number';
    print "$_ -> $ret->{$_}\n" foreach (keys %{$ret}); # just to trace
    print "$ret=$ret->{Dec}\n";                        # just to trace
    return $ret;
}
1;
#EOF
########################################################################
and a dummyscript constant.pl:
########################################################################
use constants;
my $bla = &constants::get_constant ('%month_number');
#EOF
########################################################################

when i run the script with row (<------- ODD ROW) it works fine:
bash-2.04$ perl constant.pl 
Oct -> 10
Dec -> 12
Mar -> 03
Feb -> 02
Jan -> 01
Nov -> 11
May -> 05
Aug -> 08
Sep -> 09
Jul -> 07
Apr -> 04
Jun -> 06
HASH(0x80f8270)=12

but if i remove that line i get:
bash-2.04$ perl constant.pl 
HASH(0x80f8270)=


ie it doesn't seems to find the variable...This seems like vodoo to me.
Can anyone explain or point me to a place with an explanation?


/Jon

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to