在Perl 5中,我可以创建一个字符串的文件句柄,并从字符串中读取或写入,就好像它是一个文件一样.这非常适合使用测试或模板.
例如:
use v5.10; use strict; use warnings;
my $text = "A\nB\nC\n";
open(my $fh, '<', \$text);
while(my $line = readline($fh)){
print $line;
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在Perl 6中做到这一点?以下不为Perl 6的工作(至少对于上运行我的Perl6的实例MoarVM 2015.01从Rakudo星2015年1月发布 64位的CentOS 6.5):
# Warning: This code does not work
use v6;
my $text = "A\nB\nC\n";
my $fh = $text;
while (my $line = $fh.get ) {
$line.say;
}
# Warning: Example of nonfunctional code
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
No such method 'get' for invocant of type 'Str'
in block <unit> …
Run Code Online (Sandbox Code Playgroud) 我的VS2013安装从未发生任何崩溃,但本周它在启动时开始显示此错误:
An exception has been encountered. This may be caused by an extension. You can get more information by bexamining the file (...)\AppData\Roaming\Microsoft\VisualStudio\12.0\ActivityLog.xml
Run Code Online (Sandbox Code Playgroud)
然后它正确打开,我可以正常工作.但是,当我尝试提交本地更改并打开团队资源管理器并单击CHanges时,Visual Studio崩溃.
我调查了ActivityLog.xml并发现了这个错误:
<entry>
<record>179</record>
<time>2015/02/27 17:51:35.065</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.IO.IOException: The file exists.

 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.__Error.WinIOError()

at System.IO.Path.InternalGetTempFileName(Boolean checkHost)

at Microsoft.VisualStudio.Text.Utilities.WpfHelper.LoadCursorDPIAware(Stream cursorStream)

at Microsoft.VisualStudio.Text.Editor.Implementation.LeftSelectionMargin.get_RightArrowCursor()

at Microsoft.VisualStudio.Text.Editor.Implementation.LeftSelectionMarginProvider.CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)

at Microsoft.VisualStudio.Text.Utilities.ContainerMargin.<AddMargins>b__2(IWpfTextViewMarginProvider mp)

at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata,TExtensionInstance](Object errorSource, Lazy`2 provider, Func`2 getter)</description>
</entry>
Run Code Online (Sandbox Code Playgroud)
我尝试删除我的所有项目,再次克隆它们,这仍然存在.任何人都可以帮我解决这个问题吗?
起初,我只是想知道为什么在这段代码的第2行(来自Perl 6 Advent Calendar,2018年12月25日)的空括号之前有一个冒号?
sub is-happy( $n is copy ) {
my $seen-numbers = :{};
while $n > 1 {
return False if $n ? $seen-numbers;
$seen-numbers{$n} = True;
$n = $n.comb.map(*²).sum
}
return True;
}
say is-happy(7); # True
say is-happy(2018); # False
Run Code Online (Sandbox Code Playgroud)
这段代码几乎可以立即运行.我试过say $seen-numbers.^name;
,发现它是Hash[Mu,Any]
.
但是,当我删除冒号,is-happy(7)
返回True
,但然后is-happy(2018)
将CPU绑起来几分钟(直到我杀死了进程).此外,在这种情况下,say $seen-numbers.^name;
打印Hash
.
所以,显然,:{}
导致创建一个Hash[Mu,Any]
.这是如何运作的?这是解决方案还是惯用的?什么是它Hash[Mu,Any]
和它如何与正常相比Hash
?
我正在尝试实现在Android Hello Views示例中定义的MapView示例,但现在我遇到了这个错误:
Failed to find provider info for com.google.settings
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
从目前的版本(0.98)中的驼鹿::手册:: MooseX是线路:
我们对未来寄予厚望
MooseX::Method::Signatures
和MooseX::Declare
.然而,这些模块虽然经常被社区中一些更疯狂的成员用于生产,但仍然标记为alpha,以防万一需要进行向后不兼容的更改.
我注意到2009年9月MooseX::Method::Signatures
的更改日志中提到删除了" 可怕的ALPHA免责声明 ".
那么,这些仍然是"阿尔法"吗?
我还会被认为是使用它们的"更疯狂"之一吗?
每个版本的Microsoft .NET框架都具有有限的支持生命周期,例如:
我拥有2004年使用.NET Framework 1.1编写的应用程序.如果您尝试在现代Windows 7 64位计算机上安装.NET Framework 1.1版,则会出现错误 - 它将无法正常工作.2006年编写的程序不再可用; 你不妨扔掉它.
这是否意味着我今天在.NET 3.5中编写的程序将来会在某些时候无法使用?
微软竭尽全力使用Windows API来保持向后兼容性.18年前编写的程序(适用于Win32或Win32s)仍将在今天的Windows上运行.(我知道 - 我拥有一个.它最初运行在Windows 3.1上,仍然在Windows 7 64位上运行.)
一个本地人,我今天写的程序仍然会从现在(可能)工作18年.但似乎我今天写的.NET程序无法保证它将继续运行.
Microsoft是否就.NET Framework 2.0或更高版本提出了任何兼容性承诺?我知道.NET Framework 1/1.1是一个丑陋的继子; .NET Framework 2.0破坏了与1.1的兼容性; 但是自2.0以来的每个框架都与2.0兼容.
有没有注意到如果我用.NET 2.0或更高版本编写托管应用程序,它应该继续在Windows 8,Windows 9,Windows 10等上运行?
使用Process Explorer监视程序时,我发现它正在尝试和失败的.NET对象创建:
这是班级:
{60EBA0BC-D6AF-41C2-9584-D48D3DA39999}
Engine.Factory
所以我创建了一个小测试应用程序,看看我是否可以创建相同的COM对象:
const Guid CLSID_EngineFactory = '{60EBA0BC-D6AF-41C2-9584-D48D3DA39999}';
IUnknown unk = …
Run Code Online (Sandbox Code Playgroud) 编辑:已解决!曾经想要从某个特定日期开始设置通知(当某个活动开始时或按下按钮时?)阅读更多信息以了解如何:
//Set a notification in 7 days
Calendar sevendayalarm = Calendar.getInstance();
sevendayalarm.add(Calendar.DATE, 7);
Intent intent = new Intent(this, Receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 001, intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, sevendayalarm.getTimeInMillis(), pendingIntent);
Run Code Online (Sandbox Code Playgroud)
这是Receiver类的代码
public class Receiver extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Intent intent = new Intent(this, Test.class);
long[] pattern = {0, 300, 0};
PendingIntent pi = PendingIntent.getActivity(this, 01234, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.depressiontest)
.setContentTitle("Take …
Run Code Online (Sandbox Code Playgroud) 我有一个具有唯一行名和唯一列名的数据框.我想将行转换为列,将列转换为行.
例如,这段代码:
starting_df <- data.frame(row.names= c(LETTERS[1:4]),
a = c(1:4),
b = seq(0.02,0.08,by=0.02),
c = c("Aaaa","Bbbb","Cccc","Dddd")
)
Run Code Online (Sandbox Code Playgroud)
结果如下:
> starting_df
a b c
A 1 0.02 Aaaa
B 2 0.04 Bbbb
C 3 0.06 Cccc
D 4 0.08 Dddd
Run Code Online (Sandbox Code Playgroud)
我想将它转换为包含完全相同数据的另一个数据框,除了之前的行现在是列,反之亦然:
> final_df
A B C D
a 1 2 3 4
b 0.02 0.04 0.06 0.08
c Aaaa Bbbb Cccc Dddd
Run Code Online (Sandbox Code Playgroud) 在Perl 5中,我可以使用Getopt::Long
一些验证来解析命令行参数(参见下面的http://perldoc.perl.org/Getopt/Long.html).
use Getopt::Long;
my $data = "file.dat";
my $length = 24;
my $verbose;
GetOptions ("length=i" => \$length, # numeric
"file=s" => \$data, # string
"verbose" => \$verbose) # flag
or die("Error in command line arguments\n");
say $length;
say $data;
say $verbose;
Run Code Online (Sandbox Code Playgroud)
这里=i
在"length=i"
与关联的值上创建数字类型约束,--length
并=s
在其中"file=s"
创建类似的字符串类型约束.
我如何在Perl 6中做类似的事情?
几个月前我开始使用Dist :: Zilla.但是,在YAPC :: NA,有人提到他们使用的是ShipIt.那么今天我在github的 miyagawa的cpanminus目录中注意到了一个.shipit文件,所以我决定再研究一下......
我最初的印象是ShipIt有一个Dist :: Zilla可用的子集,但我不想妄下结论.那么,对于那些对两者都有过经验的人来说,ShipIt vs Dist :: Zilla的优点/缺点是什么?