[問題] c code 轉 perl

看板Perl作者時間15年前 (2010/01/11 06:00), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
問題是如果有10個不同的random files 每個file有欄位是tag 程式的目的是將所有file的tag丟到memory以後sort 再將sort之後的tag以及對應的data印到output file 如果用c寫的話 可以使用file pointer以及fread fwrite 但如果用perl的話 有類似file pointer的概念嗎? The C code: #define tag 100 #define data 1k FILE fptr[i] = fopen(file[i]); FILE *outptr; void modify_quicksort (int &, int &, int); int a[] = malloc(sizeof(tag)*n); int buffer[] = malloc(sizeof(data)*n); int index = 0; for (i = 0, i < n, i++) fread( &a[i], sizeof(tag), fptr[i] ); while (n != index) { modify_quicksort (*(a+index), *(fptr+index), n-index); //return sorted array a[] and fptr[] fread (&buffer, sizeof(data), 1, fptr[index]); //read data from file to temporary buffer //fptr will point to the next line at the same time fwrite(&buffer, sizeof(data), 1, outptr); //write data from buffer to output file if (fptr[index] != feof()) fread (&a[index], sizeof(tag), 1, fptr[index]); else { fclose(fptr[index]); index++; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 24.6.47.62 ※ 編輯: stefany 來自: 24.6.47.62 (01/11 06:01) ※ 編輯: stefany 來自: 24.6.47.62 (01/11 06:06)
文章代碼(AID): #1BIatYk7 (Perl)
文章代碼(AID): #1BIatYk7 (Perl)