- 论坛徽章:
- 0
|
本帖最后由 hp_truth 于 2010-04-19 13:53 编辑
回复 1# sotol
试试这样:
#!/usr/local/bin/perl5
use warnings;
use strict;
use constant TUBE => 0;
use constant ELBO => 1;
my %com = ("gtype" => "TUBE");
no strict "refs";
print $com{gtype}(). "\n" if $com{gtype};
In the current implementation, scalar constants are actually inlinable subroutines. As of version 5.004 of Perl, the appropriate scalar constant is inserted directly in place of some subroutine calls, thereby saving the overhead of a subroutine call.
Constants are not private to the lexical scope in which they occur. Instead, they are simply argumentless subroutines in the symbol table of the package issuing the declaration. |
|