1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use constant = { ... } sub routine { my $mouse_mode = set_mouse_mode; ... ... END { if ( $mouse_mode ) { print UNSET_EXT_MODE_MOUSE_1005 if $mouse_mode == 3; print UNSET_SGR_EXT_MODE_MOUSE_1006 if $mouse_mode == 4; print UNSET_ANY_EVENT_MOUSE_1003; } } }
2013-05-10T07:15:18 KuerbisIn der Subroutine könnte ich auf Variablen zugreifen, die außerhalb nicht sichtbar sind:
Code (perl): (dl )1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16use constant = { ... } sub routine { my $mouse_mode = set_mouse_mode; ... ... END { if ( $mouse_mode ) { print UNSET_EXT_MODE_MOUSE_1005 if $mouse_mode == 3; print UNSET_SGR_EXT_MODE_MOUSE_1006 if $mouse_mode == 4; print UNSET_ANY_EVENT_MOUSE_1003; } } }
1 2 3 4 5 6 7 8 9 10 11 12
my $mouse_mode; sub routine { $mouse_mode = set_mouse_mode; ... } END { if ($mouse_mode) { ... } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
use strict;
use warnings;
my $x = main->new();
sub new {
my $self = bless { }, shift;
$self->{mouse_mode} = 2;
}
sub DESTROY {
my $self = shift;
if ($self->{mouse_mode} == 2) {
print "foo\n";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
package My_Package; use warnings; use strict; use Term::ReadKey; use constant { HIDE_CURSOR => "\e[?25l", SHOW_CURSOR => "\e[?25h", }; sub init { my $self = bless $_[1], $_[0]; $self->{old_handle} = select( $self->{handle_out} ); $self->{backup_flush} = $|; $| = 1; print HIDE_CURSOR if $self->{hide_cursor}; Term::ReadKey::ReadMode 'ultra-raw'; return $self; } sub DESTROY { my $self = shift; print "\n\r"; Term::ReadKey::ReadMode 'restore'; print SHOW_CURSOR if $self->{hide_cursor}; $| = $self->{backup_flush}; select( $self->{old_handle} ); } sub my_routine { my $arg = shift; $arg->{handle_out} = *STDOUT; local $SIG{'INT'} = sub { my $signame = shift; die "SIG$signame\n"; }; #init_scr( $arg ); my $init = My_Package->init( $arg ); my $s; while ( 1 ) { my $c = ReadKey 0; if ( ! defined $c ) { #end_scr(); warn "EOT\n"; return; } next if $c eq "\e"; if ( $c eq "\cC" ) { #end_scr( $arg ); #print STDERR "^C"; kill( 'INT', $$ ); return; } elsif ( $c eq "\r" ) { #end_scr( $arg ); return $s; } else { $s .= $c; print $c; } } } 1;