Usage in my test.pl:package C; use vars qw( $AUTOLOAD %const_values ); my %const_values = ( CONST_1 => 1, CONST_2 => 23, CONST_3 => 'Test', . . . ); use overload '``' => sub { return $const_values{shift} } ; # All constants can be accessed as by using AUTOLOAD sub AUTOLOAD { no strict 'refs', 'subs'; if ($AUTOLOAD =~ /.*::([A-Z]\w+)$/) { my $const_name = $1; *{$AUTOLOAD} = sub {return $const_values{$const_name}}; return $const_values{$const_name}; } return undef; } 1;
Hope that it will be usefull for you.#!/usr/bin/perl -w use C; print "Const 1:".C->CONST_1."\n"; print "Const 2:".C->CONST_2."\n"; print "Const 3:".C->CONST_3."\n"; __DATA__ Const 1: 1 Const 2: 23 Const 3: Test
--------------------------------
SV* sv_bless(SV* sv, HV* stash);
In reply to Re: How to use variables from other package?
by nite_man
in thread How to use variables from other package?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |