小编yas*_*han的帖子

如何使用perl中的对象对哈希进行排序

我需要通过查看val1这些对象上的公共属性(例如:)来对对象的哈希进行排序(或重新排列).我怎样才能做到这一点?

样品

perl

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

verilog中的case'inside'有什么用?它可以合成吗?

在verilog中,我们有'inside'的情况。它的用途是什么?它可以综合吗?

例如:

case(in) inside
  4'b0000, 4'b00?1: ; // 0 and 1,3
  [5:7]: ; // 5,6,7
  default: ;
endcase
Run Code Online (Sandbox Code Playgroud)

verilog system-verilog

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

如何使用 sprintf 在 C 中推回另一个字符串

我需要将另一对带有给定尾随模式的字符串推回/附加到 C 中的现有字符数组。为此,我愿意使用“sprintf”,如下所示。

#include <stdio.h>
#include<string.h>
int main()
{
    char my_str[1024]; // fixed length checked
    char *s1 = "abcd", *s2 = "pqrs";

    sprintf(my_str, "Hello World"); // begin part added
    sprintf(my_str, "%s , push back '%s' and '%s'.", my_str, s1, s2); // adding more to end of "my_str" (with given trailling format)
    /* here we always use 'my_str' as the first for the string format in sprintf - format starts with it */
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我遵循这种方法时,我收到“内存重叠”警告。这是一个严重的问题吗?(如内存泄漏、错误输出等)

c memory-management

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

如何解决 Perl eval() 中的“发现裸字”问题

以下代码返回“在 (eval 1) 第 1 行,靠近“*,out”的操作符预期位置找到了裸字(out 之前缺少操作符?)”

$val = 0;
$name = "abc";
$myStr = '$val = ($name =~ in.*,out [)';
eval($myStr);
Run Code Online (Sandbox Code Playgroud)

根据我的理解,我可以通过用“//”包装“in.*,out [”块来解决这个问题。

但是“in.*,out [”可以变化。(例如:用户输入)。用户可能会错过给出“//”。因此,还有其他方法来处理这个问题吗?(例如:如果 eval() 尝试返回“在...处找到裸字”,则返回 0)

regex perl eval

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

A shorter way to write following c++ code (if-else)

I need to know is there a better / shorter way to write following code in c++. (while going through the main if-else (step by step), additional check for variable 'y' will be added)

int x = 5, y = 4;        

if(x == 1){
  if(y == 1)
      printf("ok");
  else
      printf("not ok");
}
else if(x == 2){
  if((y == 1) || (y == 2))
      printf("ok");
  else
      printf("not ok");
}
else{
  if((y == 1) || (y == 2) || (y == 3)) …
Run Code Online (Sandbox Code Playgroud)

c++ optimization logic if-statement

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