Hello,

I need help to combine a c-program using curl(to retrieve txt files from internet) and another c-program using popen. currently the popen is using the command ls -l (to list the current folder in terminal).
I have 2 files, the first one is curl program,
which have to retrieve 2 text files from the internet and process them later(I haven't make the manipulation process in the code).
[CODE]#include <curl/curl.h>

include <stdio.h>
include <stdlib.h>
define DESTINATION_FILE "out.txt"
define DESTINATION_FILE2 "out2.txt"

size_t write_data( void ptr, size_t size, size_t nmeb, void stream)
{
return fwrite(ptr,size,nmeb,stream);
}

int main()
{
FILE file = fopen(DESTINATION_FILE,"w+");
FILE
file2 = fopen(DESTINATION_FILE2,"w+");
if(!file){
perror("File Open:");
exit(0);
}
CURL *handle = curl_easy_init();
curl_easy_setopt(handle,CURLOPT_URL,WEBPAGE_URL);
curl_easy_setopt(handle,CURLOPT_URL,WEBPAGE_URL2);
curl_easy_setopt(handle,CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(handle,CURLOPT_WRITEDATA, file);
curl_easy_setopt(handle,CURLOPT_WRITEDATA, file2);
curl_easy_perform(handle);
curl_easy_cleanup(handle);
}[/CODE]

and the other is popen program,
which currently is listing the contents in the folder through terminal.
[CODE]#include <stdio.h>

int main()
{
FILE *fp;
char line[130];

fp = popen("ls -l", "r");

while ( fgets( line, sizeof line, fp))
{
printf("%s", line);
}
pclose(fp);
}
[/CODE]

Now the thing is, I need to combine these 2 programs, so that only using 1 program files, I can retrieve txt files using curl as the command in popen, and can manipulate the retrieved txt files later on.

When I run the 2 program separately, it has no errors. but when I tried to combine and compile the code, it has some errors.
Here's my try:
[CODE]#include <stdio.h>

include <stdlib.h>
include ...

Thanks so much for the detailed explanations and the tutorial! I really appreciate it.

Hi, d5e5!
thanks, it works like a charm.
I have one question regarding the code,
During the first 'foreach' loop, you split each column into [ICODE]$pt[/ICODE] and [ICODE]$ps[/ICODE], and then assign the values of [ICODE]$programs{$pt}[/ICODE]into[ICODE]$ps[/ICODE].
[CODE]foreach (<$fh1>){
chomp;#Remove newline character from end of line
my ($ps, $pt) = split(/\t/);
$programs{$pt} = $ps;
}[/CODE]
[ICODE]$programs{$pt}[/ICODE] refers to the content of program session, am I correct?
and, during the 'if' loop in the second 'foreach' loop,[CODE]foreach (<$fh2>){
chomp;#Remove newline character from end of line
my $pt = (split(/\t/))[1];#Paper title
if (exists $programs{$pt}){
print $fh3 "$\t$programs{$pt}\n";
}
else{
print $fh3 "$
\tNA\n";
}
}[/CODE][ICODE]if (exists $programs{$pt}){[/ICODE]isn't that mean you're trying to check the program session whether it exists in the archive file?
I can't understand the difference between [ICODE]$programs{$pt}[/ICODE]in [ICODE]if (exists $programs{$pt}){[/ICODE] and in[ICODE]print $fh3 "$_\t$programs{$pt}\n";[/ICODE]

Hi,
I'm new to perl, and need help about comparing 2 columns within 2 different .tsv files.
I have search through the forum for some similar case of mine, such as [url]http://www.daniweb.com/software-development/perl/threads/335711[/url], [url]http://www.daniweb.com/software-development/perl/threads/336421[/url] and [url]http://www.daniweb.com/software-development/perl/threads/311399[/url] , I have tried to modified them according to my needs but somehow the final output is not right, so I decided to make a new thread.

I have 2 input tsv files,
The first one is archive.tsv. It is a paper database with the format of
[B]<Paper ID>[/B]\t[B]<Paper Title>[/B]\t[B]<Author>[/B]\t[B]<url>[/B]
[ICODE]P08-1016 Lexicalized Phonotactic Word Segmentation Margaret M. Fleck [url]http://aclweb.org/anthology-new/P/P08/P08-1016.pdf[/url]
P08-1021 Correcting Misuse of Verb Forms John Lee; Stephanie Seneff [url]http://aclweb.org/anthology-new/P/P08/P08-1021.pdf[/url]
P08-1030 Refining Event Extraction through Cross-Document Inference Heng Ji; Ralph Grishman [url]http://aclweb.org/anthology-new/P/P08/P08-1030.pdf[/url]
P08-1038 A Logical Basis for the D Combinator and Normal Form in CCG Frederick Hoyt; Jason Baldridge [url]http://aclweb.org/anthology-new/P/P08/P08-1038.pdf[/url]
P08-1039 Parsing Noun Phrase Structure with CCG David Vadas; James R. Curran [url]http://aclweb.org/anthology-new/P/P08/P08-1039.pdf[/url]
P08-1040 Sentence Simplification for Semantic Role Labeling David Vickrey; Daphne Koller [url]http://aclweb.org/anthology-new/P/P08/P08-1040.pdf[/url]
P08-1042 Ad Hoc Treebank Structures Markus Dickinson [url]http://aclweb.org/anthology-new/P/P08/P08-1042.pdf[/url]
P08-3003 Inferring Activity Time in News through Event Modeling Vladimir Eidelman [url]http://aclweb.org/anthology-new/P/P08/P08-3003.pdf[/url]
P08-5003 Semi-Supervised Learning for Natural Language Processing John Blitzer; Xiaojin Jerry Zhu [url]http://aclweb.org/anthology-new/P/P08/P08-5003.pdf[/url]
P08-5004 Advanced Online Learning for Natural Language Processing Koby Crammer [url]http://aclweb.org/anthology-new/P/P08/P08-5004.pdf[/url][/ICODE]
and the second file is program.tsv. It is a conference program database with the format of
[B]<Program Session>[/B]\t[B]<Paper Title>[/B]\t[B]<Author>[/B]
[ICODE]Information Extraction 2 Refining Event Extraction through Cross-Document Inference Ji, Heng; Ralph Grishman
Syntax & Parsing 1 A Logical Basis for the D Combinator and Normal Form ...

d5e5 commented: Good sample data and script wrapped in code tags. +9