以下Perl代码打印值:0.有没有办法解决它,除了在哈希引用传递给子例程之前向哈希添加一个虚拟键?
#!/usr/bin/perl use warnings; use strict; my $Hash; #$Hash->{Key1} = 1234; Init($Hash); printf("Value:%d\n",$Hash->{Key}); sub Init { my ($Hash) = @_; $Hash->{Key}=10; }@H_301_12@
解决方法
初始化空哈希引用.
#!/usr/bin/perl use warnings; use strict; my $Hash = {}; Init($Hash); printf("Value:%d\n",$Hash->{Key}); sub Init { my ($Hash) = @_; $Hash->{Key}=10; }@H_301_12@