Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: JA(C|P)H

by jdalbec (Deacon)
on Mar 23, 2005 at 03:00 UTC ( #441672=note: print w/replies, xml ) Need Help??

in reply to JA(C|P)H

This uses a few tricks to convert C into valid Perl. You can also do some tricks in the opposite direction using #define. Unfortunately you're limited by the fact that $ and (I think) @ are not valid characters in C code. However, gcc allows them so if you don't mind restricting the C code to gcc compilation you have more freedom.
#include <stdio.h> main() #ifdef __PERL__ ;sub main {} my $i; sub i:lvalue {$i} #endif { int i; for(i = 0; (i) < 10; (i)++){ printf("%d\n",i); } }

Replies are listed 'Best First'.
Re^2: JA(C|P)H
by ktross (Deacon) on Mar 23, 2005 at 13:35 UTC


    Thanks, this is exactly the sort of thing I was looking for. I really like the fact that you defined main as a sub. That hadn't occured to me. Using #define had crossed my mind, but I decided not to use it this time.

    What really intreges me about this example is the line: 'sub i:lvalue {$i}'. To be honest, this is the first time I've come across an lvalue sub. I know what it is doing, but not exactly how it is doing it. Documentation here I come!

    Thanks again, you've raised some interesting possibilities.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://441672]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2023-09-22 03:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found