它让我感觉很好(即在编译时间方面),Python解释器将创建字节码.pyc文件.我相信python使用某种哈希来确定源是否已更改然后重新编译.
这对Perl来说是个好主意吗?(关于具有许多依赖性的较大项目等).
// CMyDialog inherits from CDialog
void CMyFrame::OnBnClickedCreate()
{
CMyDialog* dlg = new CMyDialog();
dlg->Create( IDD_MYDIALOG, m_thisFrame );
dlg->ShowWindow( SW_SHOW );
}
Run Code Online (Sandbox Code Playgroud)
我很确定这个漏洞.我真正要问的是:当对话框被销毁时,MFC中是否存在对话清理的"魔力".如果dlg不是指针而是在堆栈上声明,它将如何工作 - 当dlg超出范围时,析构函数不会破坏窗口.
use Modern::Perl;
use DateTime;
use autodie;
my $dt;
open my $fh, '<', 'data.txt';
# get the first date from the file
while (<$fh> && !$dt) {
if ( /^(\d+:\d+:\d+)/ ) {
$dt = DateTime->new( ... );
}
print;
}
Run Code Online (Sandbox Code Playgroud)
我期待这个循环读取文件的每一行,直到读取第一个datetime值.
相反,$ _是单元化的,我得到一个"未初始化的值$ _在模式匹配"(和打印)消息.
任何想法为什么会这样?
一个
在gVim中,如果光标位于包含空格的文件名(如"C:\ Program Files\Vim\vim71\README.txt")上,那么使用'gf'会失败.
我找到了isfname选项,但文档说应该避免使用空格.
在这种情况下,我可以制作gVim打开的文件吗?
我想在这里过于聪明吗?
private static <T extends Number> Long extractLong(T value) {
if ( value < Long.MIN_VALUE || value > Long.MAX_VALUE ) { // <= compile error
throw new NumberFormatException("Conversion from " + value + " to Long will overflow");
}
return value.longValue();
}
Run Code Online (Sandbox Code Playgroud)
这会产生编译错误:
对于参数类型T,long,运算符>未定义
但是,如果我明确地执行该函数,它将编译:
private static Long extractLong(Long value) {
if ( value < Long.MIN_VALUE || value > Long.MAX_VALUE ) {
throw new NumberFormatException("Conversion from " + value + " to Long will overflow");
}
return value.longValue();
}
Run Code Online (Sandbox Code Playgroud) 只是感兴趣:有没有办法在下面的代码片段中做第二种形式的Dumper?
use Modern::Perl;
use Data::Dumper::Simple;
my $data = { name => 'jim', age => 21, updated => time() };
my $timestr = localtime($data->{updated});
say Dumper($data->{updated}, $timestr);
# output:
# $data->{updated} = 1338537112;
# $timestr = 'Fri Jun 1 08:51:52 2012';
say Dumper($data->{updated}, scalar localtime($data->{updated} ));
# compiliation error:
# say (...) interpreted as function at c:\temp\test4.pl line 9.
# syntax error at c:\temp\test4.pl line 9, near "}]"
Run Code Online (Sandbox Code Playgroud) use Modern::Perl;
use Algorithm::Permute;
use List::AllUtils qw/uniq/;
find_perms(1151);
sub find_perms {
my ($value) = @_;
my @others;
my @digits = split(//, $value);
my $perm = Algorithm::Permute->new( \@digits );
while (my @next = $perm->next()) {
my $number = join('', @next);
push @others, $number;
}
@others = sort uniq @others;
# this one works correctly
# @others = sort ( uniq( @others ));
say "FOUND @others";
}
Output:
FOUND 1115 1115 1115 1115 1115 1115 1151 1151 1151 1151 1151 1151 1511 …
Run Code Online (Sandbox Code Playgroud) 所以我发现在Vim中我的一个常见任务是将PUT连接到行的开头或行的结尾.所以我的映射可能是:
nmap <Leader>p $p
nmap <Leader>P 0P
Run Code Online (Sandbox Code Playgroud)
但是,我真正想做的是在推杆之前选择包含一个注册表.
因此,例如"a,P将从寄存器a放到行的开头.
有没有办法用映射做到这一点?
根据这个答案,int常量被隐式转换为short类型.
但在我的单元测试中,我想测试一个返回Short的getValue()函数.
assertEquals(obj.getValue(), 42);
Run Code Online (Sandbox Code Playgroud)
显然上面的方法不起作用,所以我尝试使用Short.valueOf
assertEquals(obj.getValue(), Short.valueOf(42));
Run Code Online (Sandbox Code Playgroud)
然而,这仍然抱怨 - 尽管上面提到了隐含的转换 - 所以我必须施展文字.
assertEquals(obj.getValue(), Short.valueOf((short)42));
Run Code Online (Sandbox Code Playgroud)
Short.valueOf((短)5)似乎有点乱!有更干净的方式吗?(新短片("42")同样可怕!)
我更喜欢在pl/sql块中使用这种"嵌入式"样式插入(与执行立即样式动态sql相反 - 您必须在其中分隔引号等).
-- a contrived example
PROCEDURE CreateReport( customer IN VARCHAR2, reportdate IN DATE )
BEGIN
-- drop table, create table with explicit column list
CreateReportTableForCustomer;
INSERT INTO TEMP_TABLE
VALUES ( customer, reportdate );
END;
/
Run Code Online (Sandbox Code Playgroud)
这里的问题是oracle检查'temp_table'是否存在并且它具有正确的colunms数并且如果它不存在则抛出编译错误.
所以我想知道是否有任何方式围绕这个?!基本上我想使用占位符表示表名,以欺骗oracle不检查表是否存在.
编辑:
我应该提到用户能够执行任何"报告"(如上所述).一种机制,它将执行任意查询但始终写入temp_table(在用户的模式中).因此,每次运行报告proc时,它都会删除temp_table并使用最可能的不同列列表重新创建它.
我正在使用测试框架(tut)并注意到了很多可重复性,所以我开始抽象出我需要的谓词函数.下面是一个简化的例子.
它有效,但我希望我能在一条线上完成它.问题是当我尝试实例化内联的派生谓词类时,它无法编译.有什么想法吗?
#include <string>
#include <functional>
#include <iostream>
using namespace std;
template <class T>
struct TestPredicate : public binary_function<T,T,bool>
{
virtual bool operator() (const T& expected, const T& data) const = 0;
};
template <class T>
struct IsEqual : public TestPredicate<T>
{
virtual bool operator() (const T& expected, const T& data) const
{
cout << "IsEqual: " << expected << ", " << data << endl;
return data == expected;
}
};
template <class T>
struct IsNotEqual : public TestPredicate<T> …
Run Code Online (Sandbox Code Playgroud) 我只是想知道这是否合适:
use Modern::Perl;
my @list = ('a' .. 'j');
map { func($_) } each(@list);
sub func {
my ($index, $value) = @_;
say "$index => $value";
}
Run Code Online (Sandbox Code Playgroud) 我继承了一些代码(从已经离开的人那里)并发现了这个小片段:
double minX = xVal.find('.') == string::npos ? (double)atoi(xVal.c_str()) : atof(xVal.c_str());
double minY = yVal.find('.') == string::npos ? (double)atoi(yVal.c_str()) : atof(yVal.c_str());
Run Code Online (Sandbox Code Playgroud)
他选择使用 atoi 来表示整数类型有什么原因吗?我看不出有什么问题:
double minX = atof(xVal.c_str());
double minY = atof(yVal.c_str());
Run Code Online (Sandbox Code Playgroud)
谢谢。