如何在B :: Concise中设置变量$ walkHandle

时间:2010-08-18 03:40:08

标签: perl

在我的功能中我正在做这个

my $output; 
open (MEM, '>', \$output or die "Can't open MEM: $!");
$B::Concise::walkHandle = \*MEM;

但是我收到了错误

Not a GLOB reference at C:/Perl/lib/mycrap.pm line 157.
CHECK failed--call queue aborted.

我该怎么办

1 个答案:

答案 0 :(得分:3)

不是GLOB参考 - (F)致命错误(可陷阱)

(F) Perl was trying to evaluate a reference to a "typeglob" 
(that is, a symbol table entry that looks like *foo ), 
but found a reference to something else instead. 
You can use the ref() function to find out what kind of ref it really was. 

来自Perldoc

It isn't possible to create a true reference to an IO handle 
(filehandle or dirhandle) using the backslash operator.

您可以获得的最多是对typeglob的引用,它实际上是一个完整的符号表条目。 但请参阅Perlref链接中*foo{THING}语法的说明。 但是,您仍然可以使用类型globs和globrefs,就像它们是IO句柄一样。

制作$globref = \*foo;

之类的内容

有关详细信息,请转到查看perlref

在我看到您之前的问题时,我认为您正在寻找 walk_output

lets you change the print destination from STDOUT to another open filehandle, or into a string passed as a ref (unless you've built perl with -Uuseperlio).

请参阅B::Concise& B::Concise - Walk Perl syntax tree, printing concise info about ops以获取完整示例。