本文介绍了在模块中使用$ SIG {WINCH}时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在脚本中使用此模块时,更改终端大小后,if ( $size_changed ) {仍为false.
当我直接在脚本中从模块复制代码时(这样就不必加载模块),它可以按预期工作.
不能将代码作为模块加载是什么原因?

When I use this module in a script, the if ( $size_changed ) { remains false when I've changed the terminal size.
When I copy the code from the module directly in a script (so that I don't have to load the module) it works as expected.
What could it be that loading the code as a module doesn't work?

use warnings;
use 5.014;
package My_Package;
use Exporter 'import';
our @EXPORT = qw(choose);

my $size_changed;
$SIG{WINCH} = sub { $size_changed = 1; };

sub choose {
    # ...
    # ...
    while ( 1 ) {
        my $c = getch();
        if ( $size_changed ) {
            write_screen();
            $size_changed = 0;
            next;
        }
        # ...
        # ...
    }
}

推荐答案

我想我已经找到了原因:除了这个模块之外,我还加载了另一个确实使用$SIG{WINCH}的模块.
当我不加载第二个模块时,choose子例程将按预期工作.

I think I've found the reason: apart from this module I load a second module which does use $SIG{WINCH} too.
When I don't load the second module the choose subroutine works as expected.

这篇关于在模块中使用$ SIG {WINCH}时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:53