小编Min*_*t.K的帖子

perl和bash外部命令的区别

我的name.txt包含:

Tom
Daniel
James
Run Code Online (Sandbox Code Playgroud)

在Perl,

my $names = `cat names.txt`;
print $names;
Run Code Online (Sandbox Code Playgroud)

给我:

Tom
Daniel
James
Run Code Online (Sandbox Code Playgroud)

在Bash,

names=`cat names.txt`
echo $names
Run Code Online (Sandbox Code Playgroud)

给我:

Tom Daniel James
Run Code Online (Sandbox Code Playgroud)

这是我的输出od -c name.txt:

0000000    T  o  m  \n   D   a   n   i   e   l  \n   J   a   m   e   s
0000020
Run Code Online (Sandbox Code Playgroud)

差异的原因是什么?

bash perl

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

tqdm 的总参数有什么作用?

两者有什么区别?tqdm 环绕任何可迭代对象。但是我不确定 tqdm 在给定两个参数时如何运行。

# train_ids = list
elements = ('a', 'b', 'c')
for count, ele in tqdm(enumerate(elements)):
    print(count, i)
# two arguments
for count, ele in tqdm(enumerate(elements), total=len(train_ids)):
    print(count, i)
Run Code Online (Sandbox Code Playgroud)

python tqdm

7
推荐指数
1
解决办法
9098
查看次数

获取两个无符号整数乘积的高 32 位的有效方法 c++

unsigned int a = 4294967295;  // (2^32)-1
unsigned int b = 2; 
Run Code Online (Sandbox Code Playgroud)

我试图找出获得两个无符号整数乘积的高 32 位的最有效方法。例如,使用 CUDA 编程我可以unsigned int first32bits = __umulhi(a,b)得到高 32 位。

有没有办法在 C++ 中做这样的事情?

这是我的方法:

unsigned long c = ( ((unsigned long)a * (unsigned long)b ) >> 32) & 0x00000000FFFFFFFF;
Run Code Online (Sandbox Code Playgroud)

有什么方法可以让我的方法更快吗?

c++ compiler-optimization

5
推荐指数
1
解决办法
1172
查看次数

csh脚本错误:变量名必须以字母开头

set number = $<
set n = @ $number % 2
Run Code Online (Sandbox Code Playgroud)

我是csh的新手.我只是想了解基本的东西.我收到此错误:我该set: Variable name must begin with a letter. 如何解决?

shell csh

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

Prolog Parse Tree a ^ nb ^ n

我正在尝试为语言a ^ nb ^ n创建一个解析树.

下面是我尝试过的,但它只是在不引用解析树的情况下变为真实.

%% a^n, b^n.        ex) s([a,a,b,b],[]). = true

s --> a,s,b.
s --> [].

s(ab(S)) --> a,s(S),s.
s([]) --> [].
Run Code Online (Sandbox Code Playgroud)

例如,ab(ab([]))如果我输入,我想打印s(T,[a,a,b,b],[]).

请帮忙!

prolog dcg

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

Ruby复制文件

我正在学习Ruby从学习ruby的艰难之路网站(练习17).我正在尝试将文件复制到另一个文件中.它不是复制,而是写#.请帮忙

puts "Hi, enter the file you'd like to copy"
from_file = $stdin.gets.chomp

puts "What's the name of the file you'd like to have it overwritten"
to_file = $stdin.gets.chomp

puts "You want to copy #{from_file} into #{to_file}, right?"
$stdin.gets.chomp

puts "Contents of #{from_file}:"
first_file = open(from_file)
puts first_file.read

puts "Contents of #{to_file}:"
second_file = open(to_file)
puts second_file.read

puts "now overwriting"
first_file = open(second_file, 'w')
first_file.write(second_file)

puts "Contents of #{from_file}:"
first_file = open(from_file)
puts first_file.read

puts "Contents of #{to_file}:"
second_file = …
Run Code Online (Sandbox Code Playgroud)

ruby

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

Ruby错误:参数数量错误(给定4个,预期为0)(ArgumentError)

我是一个红宝石初学者,我正在尝试制作一个称为print的方法,该方法可以打印给定数组中的所有元素。我希望我的代码收到未定义的局部变量错误。

这就是我从Youtube得到的。这给出了未定义的局部变量错误。

movies = ["good","bad"]

def good_movies
    movies.each do |movies|
        puts "I like #{movie}"
    end
end

good_movies
Run Code Online (Sandbox Code Playgroud)

我正在使用交互式Ruby。这是我的版本。

numbers = [1,2,3]

def print
    numbers.each do |number|
        puts "#{number}"
    end
end

print 
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:(irb):2:在`print'中:错误的参数数量(给定4,预期为0)(ArgumentError)。为什么我得到这个,而不是未定义的局部变量错误?

到底是怎么回事?

ruby

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

perl错误中的简单阶乘函数:在子例程外返回

我正在研究Perl中的阶乘函数.下面的代码给出了错误Can't return outside a subroutine.

factorial {
    my $n = $ARGV[0];
    if( $n <= 1 ){
        return 1;  # ----- Error Here -----
    }
    else {
        return $n * factorial($n - 1);
    }
}
Run Code Online (Sandbox Code Playgroud)

我相信我的if语句仍然在子例程中.是什么导致错误?

perl

0
推荐指数
1
解决办法
1523
查看次数

perl使用$ _无法读取文件中的每一行

我正在阅读'开始Perl:Simon Cozen的在线书'.在下面的代码中,打印注释打印了我的data.txt文件的所有行.但我的while循环不打印任何东西.请帮我解决这个问题.

open(FILE,'data.txt');
my $line = <FILE>;
my @lines = <FILE>;
print @lines;

while (<FILE>) {
    print "$_";
}
Run Code Online (Sandbox Code Playgroud)

perl

0
推荐指数
1
解决办法
114
查看次数

在阻塞中的Haskell缩进

我正在实现Hutton 编写的Haskell编程中的算术表达式树示例,我得到一个语法错误:

解析错误(可能是错误的缩进或括号不匹配)

firstgrm = do t <- secgrm
             ( do { symbol "##";
               o <- firstgrm;
           return (O (t ## o));}
        +++ return t )                         -- parse error here
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming

-2
推荐指数
1
解决办法
368
查看次数