perl typeglob使用

#!/usr/bin/perl -l


use strict;
use warnings;


my $var = "Hello Jason";
my @var = qw(aaa bbb ccc ddd eee fff);
*var = \"Hello World";
*var = \@var;
*var = sub{print "This is a sub"};
print  ${*var{SCALAR}};
map{print}@{*var{ARRAY}};
&{*var{CODE}}();
for my $field (qw/SCALAR ARRAY HASH CODE/){
        print ref *var{$field}?ref *var{$field}:"undefined";
}


sub show{
        print "This is in show()";
}


&{*show{CODE}}();

==================================================================================

output:

Hello World
aaa
bbb
ccc
ddd
eee
fff
This is a sub
SCALAR
ARRAY
undefined
CODE
This is in show()

你可能感兴趣的:(perl typeglob使用)