小编cod*_*ict的帖子

如何从Perl中的二维数组中提取数组?

我再次忘记了如何$_在二维数组的循环中表示数组.

foreach(@TWO_DIM_ARRAY){
   my @ARRAY = $_;
}
Run Code Online (Sandbox Code Playgroud)

这是意图,但这不起作用.这样做的正确方法是什么?

arrays perl multidimensional-array

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

C程序终止于-1(0xFFFFFFFF),看似没有理由?

#include <stdio.h>
typedef struct pduct {char name[20];
                        int price;
                        int stock;} PRODUCT;

void init(PRODUCT * product)
{
    printf("What is the name of the product: ");
    fgets(product->name, 20, stdin);
    printf("DEBUG: Did it get written...: %s", product->name);
    printf("What is the current stock of the item: ");
    scanf("%d", product->stock);
    printf("What is the price of the new item: ");
    scanf("%d", product->price);
}

int main()
{
    PRODUCT products[5];
    init(products);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

现在,我真的有点亏.在运行它时,它会询问产品的名称,将其打印出来,以便我知道它存储了它,然后询问库存量,它将崩溃并返回-1.

我不知道出了什么问题.我试着换出fgetsscanf,只是可以肯定的,但同样的事情发生.我猜我struct的设置错了,但我不知道怎么回事.它char可能是阵列吗?此外,无论我如何安排它,它始终是第二个输入.那么为什么第一个这么好呢?

谢谢你的帮助!

c struct pointers scanf segmentation-fault

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

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

php正则表达式查找和替换

$string = '20110306';
$pattern = '(\d{6})(\d{2})';
$replacement = '$101';
echo preg_replace($pattern, $replacement, $string);
Run Code Online (Sandbox Code Playgroud)

我希望它回应 20110301

我使用http://gskinner.com/RegExr/来提出搜索和替换模式,也许我在更换找到的模式时遗漏了一些东西.

它给了我以下警告:

消息:preg_replace()[function.preg-replace]:未知修饰符'('

php regex preg-replace

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

unix grep命令

我有一个名为"file1"的文本文件,其中包含以下数据:

apple  
appLe  
app^e  
app\^e  
Run Code Online (Sandbox Code Playgroud)

现在给出的命令是:

1.)grep app[\^lL]e file1  
2.)grep "app[\^lL]e" file1  
3.)grep "app[l\^L]e" file1  
4.)grep app[l\^L]e file1

output in 1st case : app^e

output in 2nd case :   
                     apple  
                     appLe  
                     app^e  

output in 3rd case :  
                     apple  
                     appLe  
                     app^e

output in 4th case :  
                     apple  
                     appLe  
                     app^e  
Run Code Online (Sandbox Code Playgroud)

为什么这样..?
请帮忙..!

unix grep

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

mysql选择AS

我需要做以下选择:

select distinct type as option from pages
Run Code Online (Sandbox Code Playgroud)

但我不断收到错误.你能帮我吗?

mysql reserved-words

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

程序有时会崩溃

期望以下例程在单个链表的开头删除节点,但有时会失败.

void remove_from_front(node *start)
{
    delete start;
    start = start->link;
    print_list(start);
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers linked-list data-structures

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

关于使用grep的问题

 127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/ HTTP/1.1" 200 169 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/.treeinfo HTTP/1.1" 404 182 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/Fedora HTTP/1.1" 404 182 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/Server HTTP/1.1" 404 182 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/Client HTTP/1.1" 404 182 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/RedHat HTTP/1.1" 404 182 "-" "Python-urllib/2.6"
127.0.0.1 - - [08/Mar/2011:00:26:27 +0530] "HEAD /sk/CentOS HTTP/1.1" …
Run Code Online (Sandbox Code Playgroud)

regex search grep

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

用/在Perl中拆分序列

我有一个如下所示的序列:

my $seq = "D\IKLR\LK/Q";
Run Code Online (Sandbox Code Playgroud)

我想要做的是将序列分解为单个字母.

所以我希望得到:

my $var = ['D', '\', 'I', 'K', 'L', 'R', '\', 'L', 'K','/' ,'Q'];
Run Code Online (Sandbox Code Playgroud)

但为什么这样做不会:

 my @chars = split(//,$seq);
 print Dumper \@chars;
Run Code Online (Sandbox Code Playgroud)

它改为:

my $var = ['D', '\\', 'I', 'K', 'L', 'R', '\\', 'L', 'K', 'Q'];
Run Code Online (Sandbox Code Playgroud)

做正确的方法是什么?

arrays perl split

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

链接列表创建 - 垃圾输出?

似乎无法解决为什么我在打印内容时从此链接列表结构获取垃圾输出.

我的目标是在列表中添加任何内容,一些字符串,char by char,它应该反向打印出来.我使用额外的头部+尾部结构的原因是我可以打印出反向输入的订单行.

typedef struct List {
 char c;
 struct List *next;
}List;

typedef struct  {
 List *head;
 List *tail;
}FullList;

List* InsertList(int hd, List* t1) {
 List *t = (List*)calloc(1,sizeof(List));
 t->c = hd; 
 t->next = t1;
return t;
}


FullList addToStart(FullList c, char element) {
 if (c.head == NULL) {
    c.head = c.tail = InsertList(element, NULL);
 }else {
    c.head = InsertList(element, c.head);
 }
return c;
}

int main(void) {
 FullList InOrder;
 FullList Reverse;
 InOrder.head = NULL;
 Reverse.head = …
Run Code Online (Sandbox Code Playgroud)

c pointers linked-list data-structures

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