SPUG: one of those 'other' programming languages

Mathew D. Watson matw at halcyon.com
Wed Jan 26 15:20:20 CST 2000

I looked into calling Perl from C and remember that it gets pretty hairy.
You in essence link the perl interpreter and libraries into your c program.
I got pretty scared.

On the other hand ... can you write a simple perl script that reads
'3x^5 + 2x^2 + 4'
from the standard input and then writes something like
(these are the coefficients) to the standard output? And then run the
script from within c?

My programmming skills have dipped to near nothing, but here's a crude way
to do what I have in mind:

system(" myscript.pl < equation.txt > coefficients.txt ");

Parsing the coefficient string could probably be done with ... strtok()?


At 09:49 PM 1/24/00 -0800, Ryan wrote:
>> Maybe it'll help if you floated that piece of code you're working on, so
>> can have a few 'extra pairs of eyes' look at it and give some suggestions
>> how to write an effective code.
>i would, but it's a bit of a mess...and it's c. pretty much what i wanted to
>do was make a translation method for this object we had to make.  i wanted
>it to take in something like '3x^5 + 2x^2 + 4' and spit the coefficient and
>the power out into an array.  it would be incredibly simple if c had
>regexes.  but it doesn't, so i had to write this load of 'walk through the
>char array until you find 'x', then walk backward until you hit a space,
>sticking each char into a buffer array, reverse that array, tack on a /0,
>convert it to an int, stick it in the polynomial array then go back to the x
>and blah blah blah.'
>it ballooned, and it wasn't very well written.  if anyone's still interested
>in looking at it, i've got the code here:
>and sorry about the formatting...tabs always turn a little screwy across
>different programs
Mathew D. Watson
matw at halcyon.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address

More information about the spug-list mailing list