小编Vin*_*ard的帖子

使用say函数时,为什么要指定use语句?

这个问题可能很愚蠢.但我刚开始探索Perl.我使用的是Perl v5.16.2.我知道该say声明已在5.10中引入.

#!/usr/bin/perl

say "Hello World!";
Run Code Online (Sandbox Code Playgroud)

当我尝试运行上面的程序时,我收到以下错误:

$ ./helloPerl 
String found where operator expected at ./helloPerl line 3, near "say "Hello World!""
    (Do you need to predeclare say?)
syntax error at ./helloPerl line 3, near "say "Hello World!""
Execution of ./helloPerl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

但是当我添加声明时use 5.016;,它正在给我正确的输出.

#!/usr/bin/perl

use 5.016;
say "Hello World!";
Run Code Online (Sandbox Code Playgroud)

我怀疑的是,我使用的是perl v5.16.2,它高于5.010.我为什么要use在这里使用语句提到Perl版本?

perl

15
推荐指数
2
解决办法
2617
查看次数

查找在某些但不是所有列表中出现的元素

假设我有几个整数列表,如下所示:

[0,3,4]
[2,3,4,7]
[2,3,4,6]
Run Code Online (Sandbox Code Playgroud)

什么是最有效/最pythonic方式来构建至少一个列表中但不会出现在所有列表中的所有元素的单个列表?在这种情况下,它会

[0,2,7,6]
Run Code Online (Sandbox Code Playgroud)

python

13
推荐指数
1
解决办法
360
查看次数

Haskell类型系统的细微差别

我已经深入研究了haskell类型系统的细节,并试图找到类型类的优点.我已经学会了一堆,但我在以下几段代码上打了一堵墙.

使用这些类和实例定义:

class Show a => C a where
  f :: Int -> a

instance C Integer where
  f x = 1

instance C Char where
  f x = if x < 10 then 'c' else 'd'
Run Code Online (Sandbox Code Playgroud)

为什么这会传递类型检查器:

g :: C a => a -> Int -> a
g x y = f y

yes :: C a => a -> Int -> String
yes x y = show (g x y)
Run Code Online (Sandbox Code Playgroud)

但这不是吗?

g :: C a => a -> …
Run Code Online (Sandbox Code Playgroud)

haskell types system class

12
推荐指数
3
解决办法
467
查看次数

Python列表顺序

在我编写的小脚本中,.append()函数将输入的项添加到列表的开头,而不是列表的结尾.(你可以清楚地理解,对于Python来说还是新手,所以对我来说很容易)

list.append(x)
将项添加到列表的末尾; 相当于a[len(a):] = [x].

这就是https://docs.python.org/2/tutorial/datastructures.html中所说的内容.

你可以在下面看到我的代码:

user_input = []
def getting_text(entered_text):
    if entered_text == "done":
        print "entering the texts are done!"
    else:
        getting_text(raw_input("Enter the text or write done to finish entering "))
        user_input.append(entered_text)

getting_text(raw_input("Enter the first text "))
print user_input
Run Code Online (Sandbox Code Playgroud)

我在这里误解了一些东西,因为打印功能打印c,b,a而不是a,b,c(输入输入的顺序是a,b,c)

python python-2.7

12
推荐指数
2
解决办法
1642
查看次数

将long.MaxValue转换为int并将float.MaxValue转换为int有什么区别?

我试图了解一些数据类型和转换之间的差异.

public static void ExplicitTypeConversion2()
    {
        long longValue=long.MaxValue;
        float floatValue = float.MaxValue;
        int integerValue = (int) longValue;
        int integerValue2 = (int)floatValue;
        Console.WriteLine(integerValue);
        Console.WriteLine(integerValue2);            
    }
Run Code Online (Sandbox Code Playgroud)

当我运行该代码块时,它输出:

-1
-2147483648
Run Code Online (Sandbox Code Playgroud)

我知道如果要分配给整数的值大于该整数可以保留的值,则返回整数的最小值(-2147483648).

据我所知,long.MaxValue它比一个整数的最大值大得多,但是如果我转换long.MaxValueint它,则返回-1.

这两个铸件有什么区别?我认为第一个也假设返回-2147483648而不是-1.

c# types casting

12
推荐指数
3
解决办法
2422
查看次数

如何将用户输入转换为列表?

我想知道如何获取用户输入并列出其中的每个字符.

magicInput = input('Type here: ')
Run Code Online (Sandbox Code Playgroud)

并且说你输入了"python rocks"我想让它成为这样的列表

magicList = [p,y,t,h,o,n, ,r,o,c,k,s]
Run Code Online (Sandbox Code Playgroud)

但如果我这样做:

magicInput = input('Type here: ')
magicList = [magicInput]
Run Code Online (Sandbox Code Playgroud)

magicList就是

['python rocks']
Run Code Online (Sandbox Code Playgroud)

python list python-3.x

10
推荐指数
1
解决办法
2万
查看次数

为什么CAST()函数返回错误的日期?

我试图从时间戳字段获取日期部分.我用过这个SQL查询:

select timestamp, CAST(timestamp as date) as date from messages
Run Code Online (Sandbox Code Playgroud)

我得到了以下结果:

--------------------------------------------
|        timestamp        |      date      |
--------------------------------------------
|   2016-05-15 10:22:54   |   2016-05-16   |
--------------------------------------------
Run Code Online (Sandbox Code Playgroud)

如上所示,生成的日期字段返回错误的日期,2016-05-16而原始日期是2016-05-15.

我们如何解决这个问题?

mysql sql date

10
推荐指数
3
解决办法
1172
查看次数

Behat"无法识别的选项"

我正在尝试运行Behat(第一次为我)并且它有效.

但我有配置问题.我试图改变功能和引导的路径,如下所示:

#behat.yml
default:
    paths:
        features: app/tests/features
        bootstrap: %behat.paths.features%/bootstrap
Run Code Online (Sandbox Code Playgroud)

现在我得到一个例外:

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] Unrecognized options "paths" under "testwork"
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

php behat laravel

9
推荐指数
1
解决办法
6450
查看次数

Python中str.replace函数的Big O表示法是什么?

str.replacePython中函数的大符号是什么?

总是O(n)吗?

str = "this is string example"
print str.replace("is", "was")
Run Code Online (Sandbox Code Playgroud)
thwas was string example
Run Code Online (Sandbox Code Playgroud)

python

8
推荐指数
2
解决办法
4003
查看次数

防止C++中的L值实例化14

C++ 14中的方法可以判断它们是在L值还是R值上调用:

struct A{
  A() { puts("Ctor"); }
  void m() const & { puts("L-value"); }
  void m() const && { puts("R-value"); }
};

int main(){
  A a; //Ctor
  a.m() //L-value
  A().m(); //Ctor; R-value
}
Run Code Online (Sandbox Code Playgroud)

ctor可以告诉它正在构建哪种类型?我可以完全禁用我班级的L值构造吗?

我有一个代理类(实际上是几个),它应该总是转换为其他东西.使用它而不转换是一个错误.我可以在运行时,如检测到错误,加入了bool used_ = 0;会员#ifndef NDEBUG;,并在我的用户指定的强制设置它,然后做assert(used_)代理类的Dtor,但是它会好得多,如果我能得到编译器来防止instatiation L-value的情况下,那个代理首先是:

 auto x = Proxy().method1().method2(); // no
 Proxy p; // no
 Target x = Proxy(); //yes
 Target x = Proxy().method1().method2(); //yes
Run Code Online (Sandbox Code Playgroud)

我可以用C++ 14做类似的事吗?

c++ c++14

8
推荐指数
1
解决办法
343
查看次数

标签 统计

python ×4

types ×2

behat ×1

c# ×1

c++ ×1

c++14 ×1

casting ×1

class ×1

date ×1

haskell ×1

laravel ×1

list ×1

mysql ×1

perl ×1

php ×1

python-2.7 ×1

python-3.x ×1

sql ×1

system ×1