Jemand zu Hause?Leser: 29
Term::Choose hochgeladen.
Term::Choose unterstützt in der nächsten stabilen Version auch MSWin32 OS.
Term::Choose werden Elemente der übergebenen Liste unter anderem so bearbeitet:1 2 3
if ( ref $element ) { $element = sprintf "%s(0x%x)", ref $element, $element; }
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
$ cat a.pl
#! /usr/bin/perl
use strict;
use warnings;
use CGI;
use XML::Parser::Expat;
sub foo {
my $r = shift;
# Kuerbis' Vorschlag
if ( ref $r ) {
printf "1. %s(0x%x)\n", ref($r), $r;
}
# einfache Ausgabe
printf "2. %s\n", $r;
}
# check different references and objects
for my $e ( [], {}, CGI->new, XML::Parser::Expat->new ) {
foo($e);
}
__END__
$ perl a.pl
1. ARRAY(0x94d78c4)
2. ARRAY(0x94d78c4)
1. HASH(0x9525064)
2. HASH(0x9525064)
1. CGI(0x94f05fc)
2. CGI=HASH(0x94f05fc)
1. XML::Parser::Expat(0x95284ec)
2. XML::Parser::Expat=HASH(0x95284ec)
Unicode::GCString columns()) nicht mit der tatsächlichen benötigten Länge im Terminal überein, was die Formatierung der Ausgabe durcheinander bringt.
Term::Choose von einem Script geladen, dann wird automatisch print "\e(U"; gemacht. print "\e(U" schaltet das automatische Codepage-Mapping von Windwos aus: hier wird beschrieben, was es macht.1 2 3
if ( ! exists $ENV{TC_KEEP_WINDOWS_MAPPING} || ! $ENV{TC_KEEP_WINDOWS_MAPPING} ) { print "\e(U"; }
1 2 3 4 5 6
package Term::Choose; ... if ( $Term::Choose::Keep_Win32_Codepage ) { local $| = 1; # braucht's das vielleicht noch? print "\e(U"; }
QuoteANNOUNCEMENT
This announcement has no meaning if the operating system is not a MSWin32 operating system.
If the operating system is MSWin32 Term::Choose disables the Windows own codepage conversion globally by printing the "\e(U" escape sequence - see "\e(U" in Win32::Console::ANSI.
In a future release of Term::Choose the disabling of the Windows own codepage conversion will be removed by removing the "\e(U" escape sequence.
You can already now enabling the Windows own codepage conversion by setting the environment variable TC_KEEP_WINDOWS_MAPPING to a true value.
If you want keep the Windows own codepage conversion disabled add
use Win32::Console::ANSI;
print "\e(U";
to your code.
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
use 5.010001; use warnings; use strict; use Test::More; eval "use Expect"; if ( $@ ) { plan skip_all => "Expect required for choose_1.t test."; } my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); my $command = 'perl'; my $script = 't/choose_1.pl'; my @parameters = ( $script ); ok( -r $script, "$script is readable" ); ok( -x $script, "$script is executable" ); ok( $exp->spawn( $command, @parameters ), "Spawn '$command @parameters' OK" ); $exp->send( "\x{0d}" ); my $expected = 'choice: 1'; my $ret = $exp->expect( 2, $expected ); ok( $ret, 'matched something' ); ok( $exp->match() eq $expected, "expected: '$expected', got: '" . $exp->match() . "'" ); done_testing();
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/env perl use warnings; use strict; use 5.010001; use Term::Choose qw( choose ); my $choice = choose( [ 1 ] ); say "choice: $choice";
Tipp zum Debugging