为什么在这里substr-rw切断尾随6?
#!/usr/bin/env perl6
use v6;
my $str = '123';
$str ~= '.' x 30;
$str ~= '456';
say $str; # 123..............................456
$str.substr-rw( 0, 10 ) = '';
say $str; # ........................45
Run Code Online (Sandbox Code Playgroud)
perl6 --version
This is Rakudo version 2016.03-38-g8df1a69 built on MoarVM version 2016.03-46-g50c7f6a implementing Perl 6.c.
Run Code Online (Sandbox Code Playgroud) 使用整数作为哈希键是否安全?
my %hash;
my $str = ...
for $str.NFC {
%hash{$_} = ...
}
Run Code Online (Sandbox Code Playgroud) 我如何自动与命令行程序进行交互,这些命令行程序使用Perl 6公开文本终端接口以进行测试?
在此示例中,Firebird 返回未解码的字符串。是我没有正确设置数据库还是 Firebird 就是这样工作的?
\n#!/usr/bin/env perl\nuse warnings;\nuse 5.10.0;\nuse utf8;\nuse open qw( :std :utf8 );\nuse Devel::Peek;\nuse DBI;\n\nmy ( $db, $dbh, $sth, @array );\nmy $table = 'test_encoding';\nmy $create = "CREATE TABLE $table ( name varchar(32) )";\nmy $insert = "INSERT INTO $table ( name ) VALUES ( ? )";\nmy $select = "SELECT * FROM $table";\nmy $value = '\xc3\xa4';\n\n$db = '/home/me/my_firebird_db';\n$dbh = DBI->connect(\n "dbi:Firebird:db=$db", 'user', 'password',\n { PrintError => 0, RaiseError => 1, ib_charset => 'UTF-8' }\n);\n$sth = $dbh->do( "DROP TABLE $table" );\n$sth …Run Code Online (Sandbox Code Playgroud) 当我尝试使用文件句柄作为参数的"chdir"时,"chdir"返回0并pwd返回仍然是同一目录.应该这样吗?
我试过这个,因为在chdir的文档中我发现:
"在支持fchdir的系统上,您可以传递文件句柄或目录句柄作为参数.在不支持fchdir的系统上,传递句柄会在运行时产生致命错误."
后来给出:
#!/usr/bin/perl -w
use 5.010;
use strict;
use Cwd;
say cwd(); # /home/mm
open( my $fh, '>', '/home/mm/Documents/foto.jpg' ) or die $!;
say chdir $fh; # 0
say cwd(); # /home/mm
Run Code Online (Sandbox Code Playgroud)
我认为这可能是文件目录的chdir - 但我这里没有DWIM.
当我写
#!/usr/bin/perl -w
use strict;
while( <DATA> ) {
print "\n-------------------------\n\n";
print;
<>;
}
Run Code Online (Sandbox Code Playgroud)
每次“返回”后,我得到一行。
为什么每个“返回”一段之后我都看不到下一个脚本?
#!/usr/bin/perl -w
use strict;
local $/ = "";
while( <DATA> ) {
print "\n-------------------------\n\n";
print;
<>;
}
__DATA__
line one
line two
line three
line four
line five
line six
line seven
line eigth
line nine
line ten
line eleven
line twelve
Run Code Online (Sandbox Code Playgroud) 以下脚本工作正常:
#!/usr/bin/env perl
use strict; use warnings;
use Data::Dumper;
use WWW::Mechanize;
my $loginData = "userName=username&password=password&deeplinkForward=%2Fselfcare%2Frestricted%2FprepareCoCo.do&x=84&y=7";
my $loginUrl = "https://www.login.login/login.do";
my $mech = WWW::Mechanize->new( show_progress => 1 );
my $req = $mech->post( $loginUrl, 'Content' => $loginData );
my $content = $req->content();
print Dumper $content;
Run Code Online (Sandbox Code Playgroud)
但是当我更换线路时
my $req = $mech->post( $loginUrl, 'Content' => $loginData );
Run Code Online (Sandbox Code Playgroud)
同
my %hash = (
'username' => 'username',
'password' => 'password',
'deeplinkForward' => '%2Fselfcare%2Frestricted%2FprepareCoCo.do',
'x' => '84',
'y' => '7'
);
my $req = $mech->post( $loginUrl, 'Content' …Run Code Online (Sandbox Code Playgroud) 如何在这段代码中实现超时:如果"hwinfo --usb"命令在一段时间后没有返回任何内容,(停止命令并且)从子_usb_device返回或死掉.
#!/usr/bin/env perl
use warnings;
use strict;
sub _usb_device {
my @array;
{
local $/ = "";
@array = qx( hwinfo --usb );
}
...
...
}
Run Code Online (Sandbox Code Playgroud) 在这个正则表达式的开头,像"^"或"\ A"这样的锚是否有任何意义 - 任何区别?
$string =~/(.*)([a-z])$/
Run Code Online (Sandbox Code Playgroud) sub routine1 {
return wantarray ? () : undef;
}
sub routine2 {
return;
}
Run Code Online (Sandbox Code Playgroud)
这两个子程序有什么区别吗?