in reply to Re: passing c agruments to Perl
in thread passing c agruments to Perl

I apologize I'm not following your C script very well, I used to be good in C, but I haven't used it for about 3 years. Could you make the script easier to understand.

Replies are listed 'Best First'.
Re: Re: Re: passing c agruments to Perl
by tachyon (Chancellor) on Oct 01, 2003 at 01:14 UTC

    Its not a script, it is a single function called match() You pass match two arguments - one is the string you want to check, the other the regex patern you want that string to match. The regex pattern is shown in the Perl example. The function returns 1 if it matches. I don't know how it could be simpler.

    [root@devel3 root]# cat test.c #include <stdio.h> #include <regex.h> int main(int argc, char *argv[]) { int i; char *pat = "^[A-Z]+$"; printf("Got %d args\n", argc-1 ); /* first arg prog name */ for( i=1; i<argc; i++ ) { printf("Got %s\n",argv[i]); if ( match( argv[i], pat ) ) { printf("-->Match %s\n", pat); } else { printf("***Fail\n"); } } return 0; } int match(const char *string, char *pattern) { int status; regex_t re; if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) { return(0); /* report error */ } status = regexec(&re, string, (size_t) 0, NULL, 0); regfree(&re); if (status != 0) { return(0); /* report error */ } return(1); } [root@devel3 root]# gcc test.c [root@devel3 root]# ./a.out 123 ABC abc ABC123 Got 4 args Got 123 ***Fail Got ABC -->Match ^[A-Z]+$ Got abc ***Fail Got ABC123 ***Fail [root@devel3 root]#

    I have no comprehension why you want to do data validation in C before you call a Perl script. Surely the Perl does data validation????? If so just use your C wrapper to exec the Perl script. End of story.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print