![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk and fuction (recursion) !! Urgent !! | varungupta | UNIX for Advanced & Expert Users | 12 | 04-16-2008 02:12 PM |
| about memset fuction | ranj@chn | High Level Programming | 3 | 01-31-2006 04:59 AM |
| perl "system" cmd return values.. | sekar sundaram | Shell Programming and Scripting | 0 | 11-24-2005 04:00 AM |
| Get Oracle fuction return value in a variable | rahulrathod | UNIX for Dummies Questions & Answers | 3 | 04-14-2005 09:50 AM |
| perl: why the return valure of stat and lstat are the same? | gusla | Shell Programming and Scripting | 1 | 05-30-2002 10:58 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi All,
I have a perl script(1.pl) that calls a c function defined in another file sample.c #!/usr/bin/perl my $re = 1; my @s = `/home/PERL_SCRIPTING/Rough/sample pline $re 10`; print "$_" foreach(@s); The sample.c is as bwlow: # include <stdio.h> int pline(int, int); main(int argc,char *argv[]) { int i,j; printf("Wow Entered main\n"); printf(" %s ", argv[1]); printf(" %s ", argv[2]); printf(" %s ", argv[3]); if(strcmp(argv[1],"pline") == 0) { int i,j,k; i = atoi(argv[2]); j = atoi(argv[3]); printf("value of i is %d \n",i); k = pline(i,j); printf("%d",k); } } int pline( int x, int y) { x = x + 20; printf("value of x : %d", x); printf("\n"); return(x); } I can call the c function and values are printing. But i need only the value of k to be stored in a variable in the perl script so that i can use it later in teh script. Is their any solution for this?? Thanks in advance JS |
| Forum Sponsor | ||
|
|
|
|||
|
You need to parse the output from your C program, or make its output format less complex. The fact that it might not always print a value for k seems like a slightly dubious design, if that's what it's primarily useful for. Also I'd centralize all the printing to one function, and make pline() only calculate and return the desired value (for printing or other use).
The last line of output will be in $s[-1] if that's the only output you are really interested in. |
|
|||
|
My actual code and function are different .
The code shown above is a simple example i need to implement. The point is i need to return the value of k to the perl script a and store in a variable so tha ti can use it. |
|
|||
|
Printing it and having Perl capture the output is a perfectly good way to do that, or do you think otherwise?
In theory, you could make your C function callable directly from Perl, by wrapping it in something called XS. See man perlxstut |
|
|||
|
I tried [-1] and it worked .. Because its the only point available and needed.
Thanks a lot era .. I dont know much about perl as am very new to this ..and my time is very limited that I cant do a leran and implement principle but implement and learn .. |
|||
| Google UNIX.COM |